Docker-swarm容器编排
1. 先安装docker
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#这是查看docker都要那些版本(可以不用管)
yum list docker-ce --showduplicates
yum -y install docker-ce-18.09.9 docker-ce-cli-18.09.9
yum -y install bash-completion
source /usr/share/bash-completion/bash_completion
#禁用防火墙、禁用selinux
systemctl enable --now docker && systemctl status docker
systemctl disable --now firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
grep ^SELINUX= /etc/selinux/config
2. docker-swarm初始化
[root@docker01 ~]# docker swarm init --advertise-addr 10.0.0.40
Swarm initialized: current node (yqel2ya881rt75i8pvgwtkbl6) is now a manager.
To add a worker to this swarm, run the following command:
#其它node节点分别执行这个命令加入集群
docker swarm join --token SWMTKN-1-1usvgogb8a1cmb3zxgpwp8quwtlrohh0qijwqcic8g6c48fn53-2pj9725lanuo849mcdfgdzsr6 10.0.0.40:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
#查看集群是否添加进来
[root@docker01 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
yqel2ya881rt75i8pvgwtkbl6 * docker01 Ready Active Leader 19.03.15
sz0l4yegkp4943jz6bf92ba7t docker02 Ready Active 19.03.15
uvs696abquqk7euc1eavifs8m docker03 Ready Active 19.03.15
#运行的端口2377
3. docker-swarm集群高可用
#先把集群打上标签
[root@docker01 ~]# docker node update --label-add name=swarm-master1 docker01
docker01
[root@docker01 ~]# docker node update --label-add name=swarm-node1 docker02
docker02
[root@docker01 ~]# docker node update --label-add name=swarm-node2 docker03
docker03
#提示角色权限 如果master节点宕机 node节点可以接管msater
[root@docker01 ~]# docker node promote docker02
Node docker02 promoted to a manager in the swarm.
[root@docker01 ~]# docker node promote docker03
Node docker03 promoted to a manager in the swarm.
#查看信息
[root@docker01 ~]# docker node inspect docker01
#可以停止下docker01的服务 然后docker02 docker03会选举master
[root@docker01 ~]# systemctl stop docker
4. docker-swarm创建网络
[root@docker01 ~]# docker network create -d overlay --subnet=10.220.0.0/21 --gateway=10.220.0.1 --attachable network-name
lxsiiqurwvzlc0ejv0w0zwp8u
[root@docker01 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
00d14a29f4c8 bridge bridge local
4d26921ab564 docker_gwbridge bridge local
ab9a47f52b5a host host local
gj3msmhrw6l6 ingress overlay swarm
lxsiiqurwvzl network-name overlay swarm
8a0e6b07272e none null local
5. docker-swarm创建一个服务
[root@docker01 ~]# docker service create --replicas 2 -p 8888:80 --network network-name --name nginx nginx:1.18-alpine
标签:node,--,swarm,编排,docker01,Docker,root,docker
From: https://www.cnblogs.com/yidadasre/p/16886252.html