把slave服务器移除集群 把master服务器移除集群

3.1 问题

把slave服务器移除集群
把master服务器移除集群

3.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:把slave服务器移除集群

1)在管理主机,移除slave服务器,从服务器没有槽,直接移除即可。

 [root@mgm57 ~]# redis-trib.rb  del-node 192.168.4.51:6351 f6649ea99b2f01faca26217691222c17a3854381   //执行移除命令
>>> Removing node f6649ea99b2f01faca26217691222c17a3854381 
       from cluster 192.168.4.57:6351
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node. //停止移除服务的Redis服务

2)在管理主机,查看集群信息

[root@mgm57 ~]# redis-trib.rb  info  192.168.4.51:6351
192.168.4.55:6355 (2d343a9d...) -> 3 keys | 4096 slots | 1 slaves.
192.168.4.53:6353 (9e44139c...) -> 3 keys | 4096 slots | 1 slaves.
192.168.4.52:6352 (324e05df...) -> 2 keys | 4096 slots | 1 slaves.
192.168.4.58:6358 (4fe1fa46...) -> 5 keys | 4096 slots | 0 slaves.//58主机,没有从服务器
[OK] 13 keys in 4 masters.
0.00 keys per slot on average.
[root@mgm57 ~]#

步骤二:把master服务器移除集群

1)在管理主机,先删除master服务器占用的hash槽

[root@mgm57 ~]# redis-trib.rb  reshard 192.168.4.53:6353
How many slots do you want to move (from 1 to 16384)?4096 //移除4096个数槽
What is the receiving node ID?  bc5c4e082a5a3391b634cf433a6486c867cfc44b 
    //要移动给谁的id即目标主机(这里可以随机写一个master的ID)  
Source node #1: c5e0da48f335c46a2ec199faa99b830f537dd8a0
//从谁那移动即源主机(这里写4.58的ID)  
Source node #2:done           //设置完毕
...
    Moving slot 12282 from c5e0da48f335c46a2ec199faa99b830f537dd8a0
    Moving slot 12283 from c5e0da48f335c46a2ec199faa99b830f537dd8a0
    Moving slot 12284 from c5e0da48f335c46a2ec199faa99b830f537dd8a0
    Moving slot 12285 from c5e0da48f335c46a2ec199faa99b830f537dd8a0
    Moving slot 12286 from c5e0da48f335c46a2ec199faa99b830f537dd8a0
    Moving slot 12287 from c5e0da48f335c46a2ec199faa99b830f537dd8a0
Do you want to proceed with the proposed reshard plan (yes/no)?yes //提交
... 
Moving slot 12282 from 192.168.4.58:6358 to 192.168.4.53:6353: 
Moving slot 12283 from 192.168.4.58:6358 to 192.168.4.53:6353: 
Moving slot 12284 from 192.168.4.58:6358 to 192.168.4.53:6353: 
Moving slot 12285 from 192.168.4.58:6358 to 192.168.4.53:6353: 
Moving slot 12286 from 192.168.4.58:6358 to 192.168.4.53:6353: 
Moving slot 12287 from 192.168.4.58:6358 to 192.168.4.53:6353:

2)在管理主机,查看集群信息

[root@mgm57 ~]# redis-trib.rb  info  192.168.4.51:6351
192.168.4.55:6355 (2d343a9d...) -> 3 keys | 4096 slots | 1 slaves.
192.168.4.53:6353 (9e44139c...) -> 3 keys | 4096 slots | 1 slaves.
192.168.4.52:6352 (324e05df...) -> 2 keys | 4096 slots | 1 slaves.
192.168.4.58:6358 (4fe1fa46...) -> 0 keys | 0 slots    | 0 slaves. //零个槽
[OK] 13 keys in 4 masters.
0.00 keys per slot on average.
[root@mgm57 ~]#

3)在管理主机,移除master主机

[root@mgm57 ~]# redis-trib.rb del-node 192.168.4.53:6353 \ 
 c5e0da48f335c46a2ec199faa99b830f537dd8a0    //删除谁+删除的id
>>> Removing node e081313ec843655d9bc5a17f3bed3de1dccb1d2b from cluster 192.168.4.51:6351
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
[root@mgm57 ~]#

4)在管理主机,查看集群信息

[root@mgm57 ~]# redis-trib.rb  info  192.168.4.51:6351  
192.168.4.55:6355 (2d343a9d...) -> 3 keys | 4096 slots | 1 slaves.
192.168.4.53:6353 (9e44139c...) -> 3 keys | 4096 slots | 1 slaves.
192.168.4.52:6352 (324e05df...) -> 2 keys | 4096 slots | 1 slaves.
[OK] 13 keys in 3 masters. //主服务器个数3台,没有58 
0.00 keys per slot on average.  
发布了324 篇原创文章 · 获赞 12 · 访问量 8208

猜你喜欢

转载自blog.csdn.net/weixin_45843450/article/details/105520373