Docker swarm 集群部署

x33g5p2x  于2021-10-25 转载在 Docker  
字(2.1k)|赞(0)|评价(0)|浏览(585)
环境准备

1.准备好四台虚拟机,可自己在vmvare创建或者在阿里云购买

2.之后对四台虚拟机安装docker,可在xshell上选择发送到所有对话,之后只要在一个主机上执行命令,即可同步到其他主机

开始安装

1.首先选择一个节点作为master节点,这里选择192.168.10.5

2.初始化swarm集群

docker swarm init --advertise-addr 192.168.10.5

[root@l4 ~]# docker swarm init --advertise-addr 192.168.10.5
Swarm initialized: current node (kpsnt4qat4ib6mc7axkm1fkok) is now a manager.

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

    docker swarm join --token SWMTKN-1-0o6vjc79zgadg3aw0a18ygeway7v5db21cp74q1dea3gkgl49z-4woofahaqp3z8a1mgpcduatie 192.168.10.5:2377

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

这时会发现192.168.10.5 节点是leader节点

[root@l4 ~]# docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
kpsnt4qat4ib6mc7axkm1fkok *   l4         Ready     Active         Leader           20.10.9

3.在master几点上获取生成加入worker命令,之后在worker节点运行

获取master 令牌命令 docker swarm join-token manager
获取worker令牌命令 docker swarm join-token worker

获取之后,在相应的节点执行,获取master令牌命令均需要在master执行
获取之后的命令在相应节点执行

[root@l4 ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-0o6vjc79zgadg3aw0a18ygeway7v5db21cp74q1dea3gkgl49z-bx0smnmm22qfbf5g0p05k8g9u 192.168.10.5:2377

[root@l4 ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:
    docker swarm join --token SWMTKN-1-0o6vjc79zgadg3aw0a18ygeway7v5db21cp74q1dea3gkgl49z-4woofahaqp3z8a1mgpcduatie 192.168.10.5:2377

如果想要与两个master节点,是有个master是备用的不是真正地,那么可以在主机执行获取master令牌后的命令

如在10.5上已经是master节点情况下,在10.6主机再次运行master令牌命令,发现主机10.6是备用master节点,MANAGER状态为Reachable

[root@l4 ~]# docker swarm join --token SWMTKN-1-0o6vjc79zgadg3aw0a18ygeway7v5db21cp74q1dea3gkgl49z-bx0smnmm22qfbf5g0p05k8g9u 192.168.10.5:2377
This node joined a swarm as a manager.
[root@l4 ~]# docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
kpsnt4qat4ib6mc7axkm1fkok     l4         Ready     Active         Leader           20.10.9
xq4ojhweyv5htnx88x5l9wvmc *   l4         Ready     Active         Reachable        20.10.9

之后在10.7 10.8主机执行work令牌命令

[root@l4 ~]# docker node ls
ID                            HOSTNAME   STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
kpsnt4qat4ib6mc7axkm1fkok *   l4         Ready     Active         Leader           20.10.9
sf5lcgbh6329zoogsfev4kp5d     l4         Ready     Active                          20.10.9
v566v6m67v3dpqrmciyy6ejyv     l4         Ready     Active                          20.10.9
xq4ojhweyv5htnx88x5l9wvmc     l4         Ready     Active         Reachable        20.10.9

相关文章