关闭selinux

vi /etc/selinux/config

#将 SELINUX=enforcing 改为 SELINUX=disabled

设置hostname和hosts确保服务器可以互相访问

hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2

vim /etc/hosts

192.168.1.1 hclly getaway node1
192.168.1.2 hcscf master
192.168.1.3 hcyyy node2

初始化master

docker swarm init --advertise-addr 192.168.1.2

#输出给出了其他节点加入的方法
Swarm initialized: current node (l2l8zqg7m8apds87fcdnfugwx) is now a manager.

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

    docker swarm join --token SWMTKN-1-2hjymsv28ik0d47owonqs7u9nuh5w7a09pz6j2z04bzo603gkq-9fkiku14q112wm18cop665623 192.168.1.2:2377

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

开放2377端口

iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 2377 -j ACCEPT

加入worker

docker swarm join --token SWMTKN-1-2hjymsv28ik0d47owonqs7u9nuh5w7a09pz6j2z04bzo603gkq-9fkiku14q112wm18cop665623 192.168.1.2:2377

检验

docker node list