准备3台机器:
bash
#dockermaster 192.168.31.150
sudo hostnamectl set-hostname dockermaster
#初始化主节点
docker swarm init --advertise-addr 192.168.31.150
#查看集群是否搭建成功
docker node ls
bash
#dockernode1 192.168.31.151
sudo hostnamectl set-hostname dockernode1
#添加worker工作节点1
docker swarm join --token SWMTKN-1-0bpxd6g43zq5sq3efzirib6ksvyo6g5k34bjh64dsrzywq4kld-1slos50zmy33u21maqz4ds67q 192.168.31.150:2377
bash
#dockernode2 192.168.31.152
sudo hostnamectl set-hostname dockernode2
#添加worker工作节点2
docker swarm join --token SWMTKN-1-0bpxd6g43zq5sq3efzirib6ksvyo6g5k34bjh64dsrzywq4kld-1slos50zmy33u21maqz4ds67q 192.168.31.150:2377
附:
bash
#生成工作节点加入Token
docker swarm join-token worker
#生成管理节点加入Token
docker swarm join-token manager
Portainer查看集群: