1.将一个从节点提升为主节点
[root@es1 swarm]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
lbcg0z4t2n3lgn4nld4brdsx7 * es1 Ready Active Leader 20.10.16
gtwzo26t996ht7ohfsy533l2u es2 Ready Active 20.10.16
v5zlbhia4kial3jqjadqm7xia es3 Ready Active 20.10.16
[root@es1 swarm]# docker node promote es2
Node es2 promoted to a manager in the swarm.
[root@es1 swarm]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
lbcg0z4t2n3lgn4nld4brdsx7 * es1 Ready Active Leader 20.10.16
gtwzo26t996ht7ohfsy533l2u es2 Ready Active Reachable 20.10.16
v5zlbhia4kial3jqjadqm7xia es3 Ready Active 20.10.16
2.故障转移
--主节点重启
[root@es1 swarm]# systemctl stop docker
[root@es1 swarm]# systemctl start docker
[root@es1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
lbcg0z4t2n3lgn4nld4brdsx7 * es1 Ready Active Reachable 20.10.16
gtwzo26t996ht7ohfsy533l2u es2 Ready Active Leader 20.10.16
v5zlbhia4kial3jqjadqm7xia es3 Ready Active 20.10.16
--由此可见主节点重启后:es1/es2 发生了角色转换。
3.再次进行故障转移
[root@es2 data]# systemctl stop docker
[root@es2 data]# systemctl start docker
[root@es1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
lbcg0z4t2n3lgn4nld4brdsx7 * es1 Ready Active Leader 20.10.16
gtwzo26t996ht7ohfsy533l2u es2 Ready Active Reachable 20.10.16
v5zlbhia4kial3jqjadqm7xia es3 Ready Active 20.10.16
4.将节点es2降级为工作节点
[root@es1 ~]# docker node demote es2
Manager es2 demoted in the swarm.
[root@es1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
lbcg0z4t2n3lgn4nld4brdsx7 * es1 Ready Active Leader 20.10.16
gtwzo26t996ht7ohfsy533l2u es2 Ready Active 20.10.16
v5zlbhia4kial3jqjadqm7xia es3 Ready Active 20.10.16