Docker Swarm群集

创建manager管理节点

1
2
3
4
5
6
7
8
9
10
[root@node1 ~]# docker swarm init --advertise-addr 172.16.50.18
Swarm initialized: current node (klih77lsaane04yopnerfgwel) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join \
--token SWMTKN-1-0mjxos9gl0mbcfxjthmobf2e0o65ttr7f5kqwrb21ss7alailn-4ovb6j2i8vd7nj8x7ekj6ttb1 \
172.16.50.18:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

加入worker工作节点

1
2
3
4
5
6
7
8
9
[root@node2 ~]# docker swarm join \
--token SWMTKN-1-0mjxos9gl0mbcfxjthmobf2e0o65ttr7f5kqwrb21ss7alailn-4ovb6j2i8vd7nj8x7ekj6ttb1 \
172.16.50.18:2377
This node joined a swarm as a worker.

[root@node3 ~]# docker swarm join \
--token SWMTKN-1-0mjxos9gl0mbcfxjthmobf2e0o65ttr7f5kqwrb21ss7alailn-4ovb6j2i8vd7nj8x7ekj6ttb1 \
172.16.50.18:2377
This node joined a swarm as a worker.

群集常用命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
docker swarm join-token worker   查看添加work工作节点的命令
docker node promote node2 增加一个从管理节点
docker node demote node2 降级为work工作节点
docker node ls 查看群集状态
docker service create --replicas 3 --network overlay --name web1 192.168.1.104/centos:http 创建群集服务,名为web1,复本数为3,第个节点必需添加好docker service create --mode global --name web1 192.168.1.104:5000/centos:http 以全局服务类型运行服务
docker service ls 查看服务
docker service ps <SERVICE-ID/NAME> 查看服务运行在哪个节点
docker service scale web1=2 伸缩服务副本数
docker node update --availability drain <NODE-ID> 将节点下线
docker node update --availability active <NODE-ID> 节点上线
docker node update --availability drain <NODE-ID> 排除分配任务的节点
docker swarm leave 节点退出集群<会有延迟>
docker node remove node3
docker node demote node1 将node1改变work工作模式
-------------本文结束感谢您的阅读-------------