Redis集群管理:删除节点

删除节点

添加节点的时候是先添加 node 节点到集群,然后分配槽位,删除节点的操作与添加节点的操作正好相反,是先将被删除的 Redis node 上的槽位迁移到集群中的其他 Redis node 节点上,然后再将其删除。

  • 要保证设备上没有数据,要做提前备份
  • 如果一个 Redis node 节点上的槽位没有被完全迁移,删除该 node 的时候会提示有数据且无法删除。

案例:
由于 192.168.7.101 服务器使用年限已经超过三年,已经超过厂商质保期而且硬盘出现异常报警,经运维部架构师提交方案并同开发同事开会商议,决定将现有 Redis 集群的 4 台服务器分别是192.168.40.7/192.168.40.8/192.168.40.9/192.168.40.13。将192.168.40.8 下线,三台服务器的并发写入性能足够支出未来 1-2 年的业务需求。

删除 Redis node 192.168.40.8 的操作如下:

[root@centos_7 ~]# redis-trib.rb reshard 192.168.40.7:6379
>>> Performing Cluster Check (using node 192.168.40.13:6379)
M: 2b0f3d3a03feea11f5fc0798f3e5f2988e7a57a1 192.168.40.13:6379
   slots:0-1277,5461-6998,10923-12201 (4095 slots) master
   1 additional replica(s)
S: 1476165d38606139382a2a576ea85648af439e3c 192.168.40.12:6379
   slots: (0 slots) slave
   replicates b617fef3c13eaf16a37c851d8748bdc3d2f97e67
M: b617fef3c13eaf16a37c851d8748bdc3d2f97e67 192.168.40.8:6379
   slots:6999-10922 (3924 slots) master
   1 additional replica(s)
M: 1ab9dba3b9aaeeed396ca9fd875cda0072006347 192.168.40.9:6379
   slots:12202-16383 (4182 slots) master
   1 additional replica(s)
S: a782c0f4c9e4d3d7c4340a0d2b533d8e68d2d130 192.168.40.10:6380
   slots: (0 slots) slave
   replicates 2b0f3d3a03feea11f5fc0798f3e5f2988e7a57a1
M: 84414bb35278fe4608956f35f7d9b79211752a41 192.168.40.7:6379
   slots:1278-5460 (4183 slots) master
   1 additional replica(s)
S: dfe2c4bf4413b99374c52a4478e15f26a5b7ba30 192.168.40.11:6379
   slots: (0 slots) slave
   replicates 84414bb35278fe4608956f35f7d9b79211752a41
S: 970d1e4ad835f6068f9cbc6152e6879692de4726 192.168.40.10:6379
   slots: (0 slots) slave
   replicates 1ab9dba3b9aaeeed396ca9fd875cda0072006347
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

# 移除多少的槽位,上面可以看到192.168.40.8又3924个槽位
How many slots do you want to move (from 1 to 16384)? 3924

# 将槽位分配到哪台设备上,填ID,我这里填的是192.168.40.7的ID
What is the receiving node ID? 84414bb35278fe4608956f35f7d9b79211752a41

Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:b617fef3c13eaf16a37c851d8748bdc3d2f97e67		# 槽位来自那台设备,40.8的ID
Source node #2:done		# 如果要移除多台设备的槽位,这里可以填多台的ID号,最后done表示结束
	...# 省略信息
	Moving slot 10919 from b617fef3c13eaf16a37c851d8748bdc3d2f97e67
    Moving slot 10920 from b617fef3c13eaf16a37c851d8748bdc3d2f97e67
    Moving slot 10921 from b617fef3c13eaf16a37c851d8748bdc3d2f97e67
    Moving slot 10922 from b617fef3c13eaf16a37c851d8748bdc3d2f97e67
Do you want to proceed with the proposed reshard plan (yes/no)? yes 	#是否确认
	... # 省略信息,知道结束
	Moving slot 10918 from 192.168.40.8:6379 to 192.168.40.7:6379: 
	Moving slot 10919 from 192.168.40.8:6379 to 192.168.40.7:6379: 
	Moving slot 10920 from 192.168.40.8:6379 to 192.168.40.7:6379: 
	Moving slot 10921 from 192.168.40.8:6379 to 192.168.40.7:6379: 
	Moving slot 10922 from 192.168.40.8:6379 to 192.168.40.7:6379: 

查看:

[root@centos_7 ~]# redis-trib.rb info 192.168.40.7:6379
192.168.40.7:6379 (84414bb3...) -> 0 keys | 8107 slots | 2 slaves.
192.168.40.9:6379 (1ab9dba3...) -> 0 keys | 4182 slots | 1 slaves.
192.168.40.13:6379 (2b0f3d3a...) -> 0 keys | 4095 slots | 1 slaves.
192.168.40.8:6379 (b617fef3...) -> 0 keys | 0 slots | 0 slaves.		# 看到已经没有槽位了
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.

从集群中移除40.8

使用 redis-trib.rb工具的del-node选项
格式:del-node host:port node_id

del-node        集群现有的任意一台IP:端口   要移除的设备的ID号

执行:

[root@centos_7 ~]# redis-trib.rb del-node 192.168.40.7:6379 b617fef3c13eaf16a37c851d8748bdc3d2f97e67
>>> Removing node b617fef3c13eaf16a37c851d8748bdc3d2f97e67 from cluster 192.168.40.7:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

成功!

查看集群现有信息:192.168.40.8已经备移除了

[root@centos_7 ~]# redis-trib.rb info 192.168.40.7:6379
192.168.40.7:6379 (84414bb3...) -> 0 keys | 8107 slots | 2 slaves.
192.168.40.9:6379 (1ab9dba3...) -> 0 keys | 4182 slots | 1 slaves.
192.168.40.13:6379 (2b0f3d3a...) -> 0 keys | 4095 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.

删除成功!

发布了63 篇原创文章 · 获赞 0 · 访问量 2194

猜你喜欢

转载自blog.csdn.net/qq_43058911/article/details/104823562