Fork me on GitHub

redis集群维护之动态删除节点

被迁移 Redis 服务器必须保证没有数据 

  一、下线192.168.1.8:6379,将槽位分配给192.168.1.6:6379

redis-trib.rb reshard 172.16.1.9:6379

返回如下:

>>> Performing Cluster Check (using node 192.168.1.9:6379)
S: cf090357c5adf3b887197623c3d378a7719d44f2 192.168.1.9:6379
   slots: (0 slots) slave
   replicates 50a2fc694407fd464c201daa0e7c72146fba5507
M: c1d534ff8edbfeec70778859b8cd289ec7258de6 192.168.1.5:6380
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
S: ddcc033179a02497200b5c87e2a5ee0bd1f4e2e8 192.168.1.7:6379
   slots: (0 slots) slave
   replicates eba2a74975496f8710f91b62c89afb28022df5b5
M: 50a2fc694407fd464c201daa0e7c72146fba5507 192.168.1.5:6379
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: 2feed5ccb782f6bc7c424f4892aafa19a57d1820 192.168.1.4:6379
   slots: (0 slots) slave
   replicates 286a966ff47d0aafa482bf121912027edf312157
S: 94e5fb4877b18f1bc1c22b4ff52e224aba6d0195 192.168.1.4:6380
   slots: (0 slots) slave
   replicates c1d534ff8edbfeec70778859b8cd289ec7258de6
M: 286a966ff47d0aafa482bf121912027edf312157 192.168.1.8:6379
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: eba2a74975496f8710f91b62c89afb28022df5b5 192.168.1.6:6379
   slots:12288-16383 (4096 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...

需要指定槽位往哪分1-16384,总共16384个槽位,

How many slots do you want to move (from 1 to 16384)? 4096

 接收节点ID是什么?这里写的是接受下线槽位的主机

What is the receiving node ID?eba2a74975496f8710f91b62c89afb28022df5b5

这4096的槽位是从哪个ID来的,这里写要下线的ID,这里要下线对应的ID,所以不能写all只有写done的时候才结束

Source node #1:286a966ff47d0aafa482bf121912027edf312157

  Source node #2:done

是否确定分配

Do you want to proceed with the proposed reshard plan (yes/no)? yes

查看信息

[16:19:10 root@localhost etc]#redis-trib.rb info 192.168.1.6:6379
192.168.1.6:6379 (eba2a749...) -> 0 keys | 8192 slots | 2 slaves.
192.168.1.8:6379 (286a966f...) -> 0 keys | 0 slots | 0 slaves.
192.168.1.5:6380 (c1d534ff...) -> 0 keys | 4096 slots | 1 slaves.
192.168.1.5:6379 (50a2fc69...) -> 0 keys | 4096 slots | 1 slaves.

集群中删除主机

redis-trib.rb del-node 192.168.1.7:6379 286a966ff47d0aafa482bf121912027edf312157
>>> Removing node 286a966ff47d0aafa482bf121912027edf312157 from cluster 192.168.1.7:6379
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

##前面192.168.1.7:6379指定的是当前集群中的任意一个主机的IP地址和端口,后面的ID是要删除的节点的ID

 

posted @ 2021-07-29 16:32  Alex-Lzy  阅读(140)  评论(0编辑  收藏  举报