Redis集群移除服务器
2023-03-13 本文已影响0人
技术老男孩
一、移除Slave角色主机:
说明:
- slave角色的主机的没有hash slots 直接移除即可
- 主机被移除集群后redis服务会自动停止
操作:
- 没删除之前查看信息
[root@mgm57 ~]# redis-trib.rb check 192.168.88.56:6379
| grep 192.168.88.59
S: d50aa7c1acebe69af0834f1838c8b17b2348472e 192.168.4.59:6379
- 移除slave角色主机
[root@mgm57 ~]# redis-trib.rb del-node 192.168.88.56:6379 d50aa7c1acebe69af0834f1838c8b17b2348472e
>>> Removing node d50aa7c1acebe69af0834f1838c8b17b2348472e from cluster 192.168.88.56:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node. # 把服务给停止了
- 查看集群信息
[root@mgm57 ~]# redis-trib.rb info 192.168.88.56:6379
192.168.88.53:6379 (f2c1bdb7...) -> 1 keys | 4096 slots | 1 slaves.
192.168.88.51:6379 (0eb3b7aa...) -> 1 keys | 4096 slots | 1 slaves.
192.168.88.52:6379 (a9cb8ccd...) -> 2 keys | 4096 slots | 1 slaves.
192.168.88.58:6379 (87cc1c12...) -> 2 keys | 4096 slots | 0 slaves. # 零台从服务器
[OK] 6 keys in 4 masters.
0.00 keys per slot on average.
[root@mgm57 ~]#
# host59主机查看Redis状态 (看不到了)
# 主机被移除集群后redis服务会自动停止
[root@host59 ~]# netstat -utnalp | grep redis-server
[root@host59 ~]#
二、移除master角色的主机:
说明:
- master角色的服务器会占用
hash slots
,要先释放hash slots
再执行移除主机的命令
具体操作步骤:
- 第一步:释放 hash slots (再次执行reshard命令)
- 第二步:移除主机 (执行删除主机的命令)
操作:
- 在管理主机mgm57 做释放 hash slots
# 释放 hash slots (再次执行reshard命令)
[root@mgm57 ~]# redis-trib.rb reshard 192.168.88.56:6379
# 第1个问题:释放hash slots 的个数
How many slots do you want to move (from 1 to 16384)? 4096 (host58主机占用hash slots 的个数)
# 第2个问题:接收4096的个hash slots的主数据库服务器的ID (随便给那个主服务器都可以)
What is the receiving node ID?0eb3b7aa0493a19189cba35b0c658202cc20884b
(host51主机的id ,就是把释放的4096个hash slots给主数据库服务器host51)
# 第3个问题:从那台主服务器移除4096个hash slots
Source node #1:87cc1c128166e08a16cc294758611453bbc71437 (host58主机的id)
Source node #2:done 结束指定
# 第4个问题:确认配置 yes同意 no 退出
Do you want to proceed with the proposed reshard plan (yes/no)? yes 同意
# 查看集群信息(发现host51 主服务器hash slots变多了 )
[root@mgm57 ~]# redis-trib.rb info 192.168.88.56:6379
192.168.88.53:6379 (f2c1bdb7...) -> 1 keys | 4096 slots | 1 slaves.
192.168.88.51:6379 (0eb3b7aa...) -> 3 keys | 8192 slots | 1 slaves. 槽多了
192.168.88.52:6379 (a9cb8ccd...) -> 2 keys | 4096 slots | 1 slaves.
192.168.88.58:6379 (87cc1c12...) -> 0 keys | 0 slots | 0 slaves. 一个槽也没有了
[OK] 6 keys in 4 masters.
0.00 keys per slot on average.
- 查看host58主机的id 然后删除主机 Host58
[root@mgm57 ~]# redis-trib.rb check 192.168.88.56:6379 |
grep 192.168.88.58
M: 87cc1c128166e08a16cc294758611453bbc71437 192.168.4.58:6379
[root@mgm57 ~]#
[root@mgm57 ~]# redis-trib.rb del-node 192.168.88.56:6379 87cc1c128166e08a16cc294758611453bbc71437
>>> Removing node 87cc1c128166e08a16cc294758611453bbc71437 from cluster 192.168.88.56:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# 再次查看集群信息 (没有host58 主机了 )
[root@mgm57 ~]# redis-trib.rb info 192.168.88.56:6379
192.168.88.53:6379 (f2c1bdb7...) -> 1 keys | 4096 slots | 1 slaves.
192.168.88.51:6379 (0eb3b7aa...) -> 3 keys | 8192 slots | 1 slaves.
192.168.88.52:6379 (a9cb8ccd...) -> 2 keys | 4096 slots | 1 slaves.
[OK] 6 keys in 3 masters.
0.00 keys per slot on average.