### portainer集群部署
curl -L https://downloads.portainer.io/portainer-agent-stack.yml -o portainer-agent-stack.yml
docker stack deploy -c portainer-agent-stack.yml portainer
### 搭建swarm
1、先安装docker
2、机器环境
```
192.168.239.131 marster
192.168.239.147 node1
设置主机名
在marster节点上
[root@marster ~]# hostnamectl --static set-hostname master
在node1节点上
[root@node1 ~]# hostnamectl --static set-hostname node1
```
3、格式化swarm```
[root@master ~]# docker swarm init --advertise-addr 192.168.239.131
Swarm initialized: current node (pza1tdiot2cvpaenmf9pvvq8v) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1ols0pte3ruh9n58oldkkca6rj5d52p8dcmjs2l4p4fh9perw9-5vt6wk3exxrqh6eqq92jgh5mv 192.168.239.128:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[root@master ~]# docker node ls #查看
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
pza1tdiot2cvpaenmf9pvvq8v * master Ready Active Leader 19.03.0
```
4、node节点加入
```
[root@node1 ~]# docker swarm join --token SWMTKN-1-1ols0pte3ruh9n58oldkkca6rj5d52p8dcmjs2l4p4fh9perw9-5vt6wk3exxrqh6eqq92jgh5mv 192.168.239.128:2377
This node joined a swarm as a worker.
```
5、创建nginx服务
```
#--name表示服务名称,--replicas表示副本任务数,--publish表示端口映射,将容器的80端口映射到物理机的80端口,nginx表示使用nginx镜像
[root@master ~]# docker service create --name web --publish 80:80 --replicas 3 nginx
#查看服务状态信息
[root@master ~]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
b05r6bo43rpp web replicated 3/3 nginx:latest *:80->80/tcp
[root@master ~]# docker service ps web
```