1 用法
docker swarm init [OPTIONS]
在manager0节点操作
192.168.7.102
[root@manager01 testswarm]# docker swarm init --advertise-addr 192.168.7.102
Swarm initialized: current node (v1ld63hqjtm8bx9z10bbhig5x) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1znl7nt91ucwz5doyuh53k6bhwihw7ked01804r60zfz8egg5c-5ej7hfjrflos3i4d4d49lfo4h 192.168.7.102:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
将 192.168.7.102 作为管理节点
添加其他管理节点,用docker swarm join-token manager 命令获得
[root@manager01 testswarm]# docker swarm join-token manager To add a manager to this swarm, run the following command: docker swarm join --token SWMTKN-1-1znl7nt91ucwz5doyuh53k6bhwihw7ked01804r60zfz8egg5c-7kr2iheffncoz6fqcj49n4fql 192.168.7.102:2377
在其他管理节点上执行 这个节点则作为管理节点添加进来
[root@node01 ~]# docker swarm join --token SWMTKN-1-1znl7nt91ucwz5doyuh53k6bhwihw7ked01804r60zfz8egg5c-7kr2iheffncoz6fqcj49n4fql 192.168.7.102:2377 This node joined a swarm as a manager.
离开集群,在要离家的集群上执行
docker swarm leave -f
准备
其中一台机器是经理(称为manager01
),其中两台是工人(node01和node02)
192.168.7.102 manager01 192.168.6.9 node01 192.168.6.17 node02
在manager01 执行
[root@manager01 testswarm]# docker swarm init Swarm initialized: current node (shd6lryp0b2frr9ypzbqofdib) is now a manager. To add a worker to this swarm, run the following command: docker swarm join --token SWMTKN-1-3bfwjhrg0sjsbrx8dqxez3hdmt38hmj0x18ph0w7prafw9c6fb-5hl8g51f7uimqleq7x9li5ukw 192.168.7.102:2377 To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
在 node01 和node02 上分别执行
docker swarm join --token SWMTKN-1-3bfwjhrg0sjsbrx8dqxez3hdmt38hmj0x18ph0w7prafw9c6fb-5hl8g51f7uimqleq7x9li5ukw 192.168.7.102:2377
在 manager01 上查看
[root@manager01 testswarm]# docker node ls ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION shd6lryp0b2frr9ypzbqofdib * manager01 Ready Active Leader 20.10.11 mzqgkj7ry6hvy3ef54jz83w8t node01 Ready Active 20.10.11 l6btk3f69mojxe2e6aprc9jcr node02 Ready Active 20.10.11
部署