Docker Raft协议
作者:互联网
1.了解Raft协议
Raft协议:保证大多数节点存活才可用。只要>1 ,集群至少大于3台,至少存在3个master节点,如果一个master节点挂了,则会从另外两个备节点选举。
2.具体实验操作
操作1,将主节点服务停止
1、之前Docker swarm 集群部署搭建了集群,而且有一个备master节点,现在将leader节点干掉
干掉前
[root@l4 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
kpsnt4qat4ib6mc7axkm1fkok l4 Ready Active Leader 20.10.9
sf5lcgbh6329zoogsfev4kp5d l4 Ready Active 20.10.9
v566v6m67v3dpqrmciyy6ejyv l4 Ready Active 20.10.9
xq4ojhweyv5htnx88x5l9wvmc * l4 Ready Active Reachable 20.10.9
[root@l4 ~]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
发现其他主机获取不到节点信息,说明另外一个主节点不能使用了
[root@l4 ~]# docker node ls
Error response from daemon: rpc error: code = DeadlineExceeded desc = context deadline exceeded
重新启动之前干掉的master节点
[root@l4 ~]# systemctl start docker
再次获取node节点信息,发现之前的备主节点已经是主节点了
操作2,将worker节点停掉,变成master节点
1.将10.7移除集群
[root@l4 ~]# docker swarm leave
Node left the swarm.
发现10.7主机状态已经是Down
[root@l4 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
kpsnt4qat4ib6mc7axkm1fkok l4 Ready Active Reachable 20.10.9
sf5lcgbh6329zoogsfev4kp5d l4 Down Active 20.10.9
v566v6m67v3dpqrmciyy6ejyv l4 Ready Active 20.10.9
xq4ojhweyv5htnx88x5l9wvmc * l4 Ready Active Leader 20.10.9
2.之后将10.7变成备主节点
主节点和备主节点都可以执行获取master令牌命令,worker节点不行
[root@l4 ~]# docker swarm join-token manager
Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
[root@l4 ~]# docker swarm join --token SWMTKN-1-0o6vjc79zgadg3aw0a18ygeway7v5db21cp74q1dea3gkgl49z-bx0smnmm22qfbf5g0p05k8g9u 192.168.10.6:2377
This node joined a swarm as a manager.
3.现在集群节点状态,有三个节点是主节点(1主,两备)
[root@l4 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
kpsnt4qat4ib6mc7axkm1fkok l4 Ready Active Reachable 20.10.9
lqu6ybb2l3sals78rtgv0tv0t * l4 Ready Active Reachable 20.10.9
sf5lcgbh6329zoogsfev4kp5d l4 Down Active 20.10.9
v566v6m67v3dpqrmciyy6ejyv l4 Ready Active 20.10.9
xq4ojhweyv5htnx88x5l9wvmc l4 Ready Active Leader 20.10.9
4.将主节点10.6 docker服务停掉,查看
[root@l4 ~]# systemctl stop docker
Warning: Stopping docker.service, but it can still be activated by:
docker.socket
之后查看节点信息,发现可以查看到,而且主节点已经变成其他主机了
[root@l4 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
kpsnt4qat4ib6mc7axkm1fkok l4 Ready Active Reachable 20.10.9
lqu6ybb2l3sals78rtgv0tv0t * l4 Ready Active Leader 20.10.9
sf5lcgbh6329zoogsfev4kp5d l4 Down Active 20.10.9
v566v6m67v3dpqrmciyy6ejyv l4 Ready Active 20.10.9
xq4ojhweyv5htnx88x5l9wvmc l4 Unknown Active Unreachable 20.10.9
再次干掉leader节点 则不能再被使用
标签:协议,20.10,节点,Ready,l4,Active,Raft,Docker,docker 来源: https://blog.csdn.net/qq_38304320/article/details/120919129