NoSQL数据库分布式@架构师redis

Redis集群移除服务器

2023-03-13  本文已影响0人  技术老男孩

一、移除Slave角色主机:

说明:

操作:

[root@mgm57 ~]# redis-trib.rb check 192.168.88.56:6379 
| grep 192.168.88.59
S: d50aa7c1acebe69af0834f1838c8b17b2348472e 192.168.4.59:6379
[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角色的主机:

说明:

具体操作步骤:

操作:

# 释放 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.
[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.
上一篇下一篇

猜你喜欢

热点阅读