目标机器
一共有七台目标机器,其中一台将作为manager,其他机器为worker
172.22.122.21 --Leader
172.22.122.22
172.22.122.23
172.22.122.24
172.22.122.25
172.22.122.26
172.22.122.27
为了能使机器之间能够更容易的识别,我们修改各台机器的hostname为机器的IP:
hostnamectl set-hostname 172.22.122.21
hostnamectl set-hostname 172.22.122.22
hostnamectl set-hostname 172.22.122.23
hostnamectl set-hostname 172.22.122.24
hostnamectl set-hostname 172.22.122.25
hostnamectl set-hostname 172.22.122.26
hostnamectl set-hostname 172.22.122.27
修改之后重新启动各台机器上的Docker服务:
[root@172 ~]# service docker restart
搭建Swarm集群
进入主机器,执行以下命令
docker swarm init --advertise-addr 172.22.122.21
将会得到的如下的结果
[root@172 ~]# docker swarm init --advertise-addr 172.22.122.21
Swarm initialized: current node (ltt783bacon1ej5rndr77mfgt) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-66ap61oi89erjgh5ucgz74u0nqmek1sjj72ak0alfd7mwnp221-0xb3gx9jm817geqfhysqpuobm 172.22.122.21:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
复制其中的
docker swarm join --token SWMTKN-1-66ap61oi89erjgh5ucgz74u0nqmek1sjj72ak0alfd7mwnp221-0xb3gx9jm817geqfhysqpuobm 172.22.122.21:2377
这一句,将这一句在所有其他节点上执行一遍。执行结束后,我们可以查看我们刚搭建好的集群:
[root@172 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
ltt783bacon1ej5rndr77mfgt * 172.22.122.21 Ready Active Leader 18.09.3
79zgd9y87t8yq153qkc21oibg 172.22.122.22 Ready Active 17.03.1-ce
nkgb2zob7sb1406fddfk5uc3u 172.22.122.23 Ready Active 17.03.1-ce
gnr0d2sulj2d4b5n31dkn35qf 172.22.122.24 Ready Active 17.03.1-ce
r50q3mcw0k4og7qo02l8k92hw 172.22.122.25 Ready Active 17.03.3-ce
otqnngsdolmurd739k3edfdm4 172.22.122.26 Ready Active 17.03.1-ce
18x0jw7ywhwm937oevfadhaud 172.22.122.27 Ready Active 17.03.1-ce
网友评论