使用Dockers部署Nacos集群
前置条件:
-
多个机器节点
-
每个节点已经安装已经安装docker
准备机器
## 修改每个master节点的hostname
ip ad |grep -E 'ens33$' |awk '{print$2}' |sed 's/\(.*\)\/.*/swarm\.master\.\1/' |xargs hostnamectl set-hostname
## 修改每个work节点的hostname
ip ad |grep -E 'ens33$' |awk '{print$2}' |sed 's/\(.*\)\/.*/swarm\.work\.\1/' |xargs hostnamectl set-hostname
## 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
初始化集群
[root@localhost ~]# docker swarm init
Swarm initialized: current node (29mvlm64mr28njsgfqrscht6x) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3s4bheco70rkawcgt3ix1pw90zkxclr1v4dv2yr51kh93g189w-dt31nfoxxmelzvrubghvqq12x 10.2.1.22:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
加入集群
[root@localhost ~]# docker swarm join --token SWMTKN-1-3s4bheco70rkawcgt3ix1pw90zkxclr1v4dv2yr51kh93g189w-dt31nfoxxmelzvrubghvqq12x 10.2.1.22:2377
This node joined a swarm as a worker.
校验
[root@localhost ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
29mvlm64mr28njsgfqrscht6x * swarm.master.10.2.1.22 Ready Active Leader 24.0.6
thw3aczwmzfurs3ec0ykpnvi1 swarm.worker.10.2.1.23 Ready Active 24.0.6
常用操作
## 查看所有节点
[root@localhost ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
29mvlm64mr28njsgfqrscht6x * swarm.master.10.2.1.22 Ready Active Leader 24.0.6
thw3aczwmzfurs3ec0ykpnvi1 swarm.worker.10.2.1.23 Ready Active 24.0.6
## 给节点添加标签
[root@localhost ~]# docker node update --label-add swarm=worker thw3aczwmzfurs3ec0ykpnvi1
thw3aczwmzfurs3ec0ykpnvi1
## 根据标签查看节点
[root@localhost ~]# docker node ls -f 'node.label=swarm'
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
thw3aczwmzfurs3ec0ykpnvi1 swarm.worker.10.2.1.23 Ready Active 24.0.6
标签:node,初始化,##,swarm,DockerSwarm,集群,docker,root,localhost
From: https://www.cnblogs.com/xysgo/p/18035824