资源列表
全部安装好docker12版本以上
节点设置 | ip | ||
manager | 172.25.11.250 | ||
slave1 | 172.25.11.1 | ||
slave2 | 172.25.11.2 |
master端
systemctl start docker
[root@foundation11 ~]# docker swarm init --advertise-addr 172.25.11.250
Swarm initialized: current node (c4162hgizv7lmzrzia2kh32q1) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-51jzyshkdpkmrlyxd7bw7qgx2ntlcktwwp834vw5yj01x4oacp-05x058cjm0sz6j8ffso0hw5ae 172.25.11.250:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
所有slave端
[root@server1 ~]# docker swarm join --token SWMTKN-1-51jzyshkdpkmrlyxd7bw7qgx2ntlcktwwp834vw5yj01x4oacp-05x058cjm0sz6j8ffso0hw5ae 172.25.11.250:2377
This node joined a swarm as a worker.
[root@server2 ~]# docker swarm join --token SWMTKN-1-51jzyshkdpkmrlyxd7bw7qgx2ntlcktwwp834vw5yj01x4oacp-05x058cjm0sz6j8ffso0hw5ae 172.25.11.250:2377
This node joined a swarm as a worker.
[root@foundation11 iso]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
c4162hgizv7lmzrzia2kh32q1 * foundation11.ilt.example.com Ready Active Leader 18.06.1-ce
r2e7dhqke64pzud5hsw7uvjpo server1 Ready Active 18.03.1-ce
lbxk5dq6q82c0m4mev6itu1sr server2 Ready Active 18.03.1-ce
[root@foundation11 iso]# docker service create --replicas 1 --name game game2048
image game2048:latest could not be accessed on a registry to record
its digest. Each node will access game2048:latest independently,
possibly leading to different nodes running different
versions of the image.
xpnxpuwuu6hxrfgrzsyns1d6w
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converged
[root@foundation11 iso]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
xpnxpuwuu6hx game replicated 1/1 game2048:latest
查看服务
[root@foundation11 iso]# docker service ps -f 'desired-state=running' game
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
titih9ew7gz1 game.1 game2048:latest foundation11.ilt.example.com Running Running 2 minutes ago
扩容
[root@foundation11 iso]# docker service scale game=4
game scaled to 4
overall progress: 4 out of 4 tasks
1/4: running [==================================================>]
2/4: running [==================================================>]
3/4: running [==================================================>]
4/4: running [==================================================>]
verify: Service converged
移除节点(drain 排除 pause 挂起 active 正常)
docker node update --availability drain server1
[root@foundation11 iso]# docker service ps -f 'desired-state=running' game
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
jjdp91yu7gvt game.1 game2048:latest Running Pending 31 seconds ago "no suitable node (3 nodes not…"
ip0f4gvbrm6u game.2 game2048:latest Running Pending 31 seconds ago "no suitable node (3 nodes not…"
mo8t0n5fhop0 game.3 game2048:latest Running Pending 31 seconds ago "no suitable node (3 nodes not…"
9d8smvo998pd game.4 game2048:latest Running Pending 31 seconds ago "no suitable node (3 nodes not…"
不小心全部移出了
docker service rm game
下面恢复
使用nginx服务
[root@foundation11 iso]# docker service create --replicas 3 --name nginx centos_nginx:v1
image centos_nginx:v1 could not be accessed on a registry to record
its digest. Each node will access centos_nginx:v1 independently,
possibly leading to different nodes running different
versions of the image.
r66t1rwdlaspifbjxapim9sm5
滚动更新
[root@foundation11 iso]# docker service create --replicas 3 --name nginx --update-delay 10s centos_nginx:v1
image centos_nginx:v1 could not be accessed on a registry to record
its digest. Each node will access centos_nginx:v1 independently,
possibly leading to different nodes running different
versions of the image.
ll5hiww3p9seedh0sw8cir8z2
overall progress: 0 out of 3 tasks
1/3: preparing [=================================> ]
2/3: preparing [=================================> ]
3/3: preparing [=================================> ]
遇到问题一直循环preparing