redis cluster 迁移数据

现有环境

实验背景:

  • CentOS Linux release 7.3.1611
  • redis 4.0.6
  • 192.168.1.116
  • 192.168.1.117

redis信息:

  • 192.168.1.116
    • 192.168.1.116:7000
    • 192.168.1.116:7001
    • 192.168.1.116:7002
    • 192.168.1.116:7003
    • 192.168.1.116:7004
    • 192.168.1.116:7005
  • 192.168.1.117
    • 192.168.1.117:7000
    • 192.168.1.117:7001
    • 192.168.1.117:7002
    • 192.168.1.117:7003
    • 192.168.1.117:7004
    • 192.168.1.117:7005

现在在两台服务器上分别部署redis cluster三主三从集群环境,模拟生产环境迁移.

迁移计划: 将192.168.1.116上的数据迁移到192.168.1.117的新建集群上, 192.168.1.117的redis要设置好集群模式,但是不要创建新集群

开始迁移

制造数据

# 使用脚本生成2万条key value
[root@localhost redis-cluster]# cat sedkey.sh 
#!/bin/bash
for ((i=0;i<20000;i++))
do
echo -en "helloworld" | redis-cli -h 192.168.1.116 -p 7000 -c -x set name$i >>redis.log
done

[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7000 dbsize
(integer) 6652
[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7001 dbsize
(integer) 6665
[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7002 dbsize
(integer) 6683
[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7003 dbsize
(integer) 6683
[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7004 dbsize
(integer) 6652
[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7005 dbsize
(integer) 6665

# 计算key是否2w条
[root@localhost redis-cluster]# python
Python 2.7.5 (default, Jul 13 2018, 13:06:57) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 6652 + 6665 + 6683
20000

查看旧集群信息

旧集群master和slave分布
[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7000 cluster nodes 
fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab 192.168.1.116:7005@17005 slave 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 0 1545035376878 6 connected
bef4dddc01651d64b5bb3e0ac384c0eb120aa537 192.168.1.116:7004@17004 slave 0607089e5bb3192563bd8082ff230b0eb27fbfeb 0 1545035377880 4 connected
17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001@17001 master - 0 1545035374876 3 connected 10923-16383
17ee6bd4c68235d09acf2f4b18ae3fcc649d629c 192.168.1.116:7002@17002 slave c433ff1b448fbcd3234632712643bc68d5213e3b 0 1545035376000 5 connected
c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003@17003 master - 0 1545035374000 2 connected 5461-10922
0607089e5bb3192563bd8082ff230b0eb27fbfeb 192.168.1.116:7000@17000 myself,master - 0 1545035373000 1 connected 0-5460

添加mater节点到旧集群中

# 新装的6个redis节点不要做集群,安装好就可以
# 像旧集群中添加mater节点
[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb add-node  192.168.1.117:7000 192.168.1.116:7000
>>> Adding node 192.168.1.117:7000 to cluster 192.168.1.116:7000
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.1.117:7000 to make it join the cluster.
[OK] New node added correctly.

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb add-node  192.168.1.117:7002 192.168.1.116:7000
>>> Adding node 192.168.1.117:7002 to cluster 192.168.1.116:7000
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.1.117:7002 to make it join the cluster.
[OK] New node added correctly.


[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb add-node  192.168.1.117:7004 192.168.1.116:7000
>>> Adding node 192.168.1.117:7004 to cluster 192.168.1.116:7000
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.1.117:7004 to make it join the cluster.
[OK] New node added correctly.

添加slave节点到旧集群中

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb add-node --slave 192.168.1.117:7001 192.168.1.117:7000
>>> Adding node 192.168.1.117:7001 to cluster 192.168.1.117:7000
[OK] All 16384 slots covered.
Automatically selected master 192.168.1.117:7000
>>> Send CLUSTER MEET to node 192.168.1.117:7001 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.168.1.117:7000.
[OK] New node added correctly.

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb add-node --slave 192.168.1.117:7003 192.168.1.117:7002
>>> Adding node 192.168.1.117:7003 to cluster 192.168.1.117:7002
[OK] All 16384 slots covered.
Automatically selected master 192.168.1.117:7002
>>> Send CLUSTER MEET to node 192.168.1.117:7003 to make it join the cluster.
Waiting for the cluster to join.^[[A
>>> Configure node as replica of 192.168.1.117:7002.
[OK] New node added correctly.

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb add-node --slave 192.168.1.117:7005 192.168.1.117:7004
>>> Adding node 192.168.1.117:7005 to cluster 192.168.1.117:7004
[OK] All 16384 slots covered.
Automatically selected master 192.168.1.117:7004
>>> Send CLUSTER MEET to node 192.168.1.117:7005 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.168.1.117:7004.
[OK] New node added correctly.

查看最新的集群状态

[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7000 cluster nodes
bef4dddc01651d64b5bb3e0ac384c0eb120aa537 192.168.1.116:7004@17004 slave 0607089e5bb3192563bd8082ff230b0eb27fbfeb 0 1545036233000 4 connected
fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab 192.168.1.116:7005@17005 slave 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 0 1545036231551 6 connected
c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003@17003 master - 0 1545036231000 2 connected 5461-10922
17ee6bd4c68235d09acf2f4b18ae3fcc649d629c 192.168.1.116:7002@17002 slave c433ff1b448fbcd3234632712643bc68d5213e3b 0 1545036232000 5 connected
a6d7dacd679a96fd79b7de552428a63610d620e6 192.168.1.117:7000@17000 master - 0 1545036236960 0 connected
2579ab004e277ba68197d851d47d0436e0cf203d 192.168.1.117:7005@17005 slave 63893e74e6f8e2414eba97b094a80ae8b3caeb09 0 1545036233955 8 connected
e010d410223a2376d3308a68a724bac27ef8d74f 192.168.1.117:7001@17001 slave a6d7dacd679a96fd79b7de552428a63610d620e6 0 1545036235958 0 connected
63893e74e6f8e2414eba97b094a80ae8b3caeb09 192.168.1.117:7004@17004 master - 0 1545036234000 8 connected
17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001@17001 master - 0 1545036234957 3 connected 10923-16383
8540a78c666cb1e81fb2821d112f3040542af056 192.168.1.117:7002@17002 master - 0 1545036233000 7 connected
1ebeedb98619bc88bf36acbbe4a766f2f74e629f 192.168.1.117:7003@17003 slave 8540a78c666cb1e81fb2821d112f3040542af056 0 1545036231952 7 connected
0607089e5bb3192563bd8082ff230b0eb27fbfeb 192.168.1.116:7000@17000 myself,master - 0 1545036234000 1 connected 0-5460

[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7000 cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:12
cluster_size:3
cluster_current_epoch:10
cluster_my_epoch:1
cluster_stats_messages_ping_sent:19905
cluster_stats_messages_pong_sent:21355
cluster_stats_messages_sent:41260
cluster_stats_messages_ping_received:21344
cluster_stats_messages_pong_received:19905
cluster_stats_messages_meet_received:11
cluster_stats_messages_received:41260

查看现有分槽情况

# 可以看到117:7000,117:7002,117:7004目前都是空槽
[root@localhost redis-cluster]# redis-cli -h 192.168.1.116 -p 7000 cluster nodes|grep master
c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003@17003 master - 0 1545036369126 2 connected 5461-10922
a6d7dacd679a96fd79b7de552428a63610d620e6 192.168.1.117:7000@17000 master - 0 1545036371000 0 connected
63893e74e6f8e2414eba97b094a80ae8b3caeb09 192.168.1.117:7004@17004 master - 0 1545036371000 8 connected
17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001@17001 master - 0 1545036371130 3 connected 10923-16383
8540a78c666cb1e81fb2821d112f3040542af056 192.168.1.117:7002@17002 master - 0 1545036373133 7 connected
0607089e5bb3192563bd8082ff230b0eb27fbfeb 192.168.1.116:7000@17000 myself,master - 0 1545036370000 1 connected 0-5460

# 共有2w个key在6个master中
[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb info 192.168.1.116:7000
192.168.1.116:7000 (0607089e...) -> 6652 keys | 5461 slots | 1 slaves.
192.168.1.116:7003 (c433ff1b...) -> 6683 keys | 5462 slots | 1 slaves.
192.168.1.117:7000 (a6d7dacd...) -> 0 keys | 0 slots | 1 slaves.
192.168.1.117:7004 (63893e74...) -> 0 keys | 0 slots | 1 slaves.
192.168.1.116:7001 (17831f8b...) -> 6665 keys | 5461 slots | 1 slaves.
192.168.1.117:7002 (8540a78c...) -> 0 keys | 0 slots | 1 slaves.
[OK] 20000 keys in 6 masters.

重新分配master节点分配slot

将192.168.1.116:7000的slot全部分配(5461)给192.168.1.117:7000

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb reshard 192.168.1.117:7000
How many slots do you want to move (from 1 to 16384)? 5461      # 分配多少数量的slot
What is the receiving node ID? a6d7dacd679a96fd79b7de552428a63610d620e6   # 上面那些数量的slot被哪个节点接收。这里填写192.168.1.117:7000节点ID
  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:0607089e5bb3192563bd8082ff230b0eb27fbfeb #指从哪个节点分配上面指定数量的slot。这里填写192.168.1.116:7000的ID。如果填写all,则表示从之前所有master节点中抽取上面指定数量的slot。
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 0 from 192.168.1.116:7000 to 192.168.1.117:7000: 
[ERR] Calling MIGRATE: ERR Syntax error, try CLIENT (LIST | KILL | GETNAME | SETNAME | PAUSE | REPLY)

解决报错

[root@localhost redis-cluster]# cp redis-4.0.6/src/redis-trib.rb redis-4.0.6/src/redis-trib.rb.bak

将redis-trib.rb文件中原来的
                source.r.client.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:keys,*keys])
                    source.r.client.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:replace,:keys,*keys])
改为
                source.r.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,"replace",:keys,*keys])
                    source.r.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:replace,:keys,*keys])

[root@localhost redis-cluster]# cat redis-4.0.6/src/redis-trib.rb |grep  source.r.call      
                source.r.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,"replace",:keys,*keys])
                    source.r.call(["migrate",target.info[:host],target.info[:port],"",0,@timeout,:replace,:keys,*keys])

# 修改后继续报错
[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb reshard 192.168.1.117:7000
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
[WARNING] Node 192.168.1.117:7000 has slots in importing state (0).
[WARNING] Node 192.168.1.116:7000 has slots in migrating state (0).
[WARNING] The following slots are open: 0
>>> Check slots coverage...
[OK] All 16384 slots covered.
*** Please fix your cluster problems before resharding

# 解决办法
[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-cli -h 192.168.1.117 -c -p 7000
192.168.1.117:7000> cluster setslot 0 stable  #The following slots are open: 0 这里是多少就写多少
OK
192.168.1.117:7000> exit
[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-cli -h 192.168.1.116 -c -p 7000  
192.168.1.116:7000> cluster setslot 0 stable  #The following slots are open: 0 这里是多少就写多少
OK
192.168.1.116:7000> exit

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb fix 192.168.1.117:7000
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

在重新分槽

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb reshard 192.168.1.117:7000
How many slots do you want to move (from 1 to 16384)? 5461      # 分配多少数量的slot
What is the receiving node ID? a6d7dacd679a96fd79b7de552428a63610d620e6   # 上面那些数量的slot被哪个节点接收。这里填写192.168.1.117:7000节点ID
  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:0607089e5bb3192563bd8082ff230b0eb27fbfeb #指从哪个节点分配上面指定数量的slot。这里填写192.168.1.116:7000的ID。如果填写all,则表示从之前所有master节点中抽取上面指定数量的slot。
Source node #2:done
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 5457 from 192.168.1.116:7000 to 192.168.1.117:7000: ..
Moving slot 5458 from 192.168.1.116:7000 to 192.168.1.117:7000: .
Moving slot 5459 from 192.168.1.116:7000 to 192.168.1.117:7000: 
Moving slot 5460 from 192.168.1.116:7000 to 192.168.1.117:7000: ..

检查分槽结果

# 可以看到 192.168.1.116:7000 上的slot已经移动到 192.168.1.117:7000节点了
[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb info 192.168.1.117:7000   
192.168.1.117:7000 (a6d7dacd...) -> 6652 keys | 5461 slots | 2 slaves.
192.168.1.117:7004 (63893e74...) -> 0 keys | 0 slots | 1 slaves.
192.168.1.117:7002 (8540a78c...) -> 0 keys | 0 slots | 1 slaves.
192.168.1.116:7001 (17831f8b...) -> 6665 keys | 5461 slots | 1 slaves.
192.168.1.116:7003 (c433ff1b...) -> 6683 keys | 5462 slots | 1 slaves.
192.168.1.116:7000 (0607089e...) -> 0 keys | 0 slots | 0 slaves.

将192.168.1.116:7001的slot全部分配(5461)给192.168.1.117:7002

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb reshard 192.168.1.117:7002
How many slots do you want to move (from 1 to 16384)? 5461
What is the receiving node ID? 8540a78c666cb1e81fb2821d112f3040542af056
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:17831f8bbcd43ac05efc5486ebfcdbb210ce48f0
Source node #2:done
......
    Moving slot 16381 from 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0
    Moving slot 16382 from 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0
    Moving slot 16383 from 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0
Do you want to proceed with the proposed reshard plan (yes/no)? yes
......
Moving slot 16381 from 192.168.1.116:7001 to 192.168.1.117:7002: 
Moving slot 16382 from 192.168.1.116:7001 to 192.168.1.117:7002: .
Moving slot 16383 from 192.168.1.116:7001 to 192.168.1.117:7002: ..

将192.168.1.116:7003的slot全部分配(5462)给192.168.1.117:7004

[root@localhost redis-cluster]# ./redis-4.0.6/src/redis-trib.rb reshard 192.168.1.117:7004
How many slots do you want to move (from 1 to 16384)? 5462
What is the receiving node ID? 63893e74e6f8e2414eba97b094a80ae8b3caeb09
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:c433ff1b448fbcd3234632712643bc68d5213e3b
Source node #2:done
......
    Moving slot 10920 from c433ff1b448fbcd3234632712643bc68d5213e3b
    Moving slot 10921 from c433ff1b448fbcd3234632712643bc68d5213e3b
    Moving slot 10922 from c433ff1b448fbcd3234632712643bc68d5213e3b
Do you want to proceed with the proposed reshard plan (yes/no)? yes
......
Moving slot 10920 from 192.168.1.116:7003 to 192.168.1.117:7004: ..
Moving slot 10921 from 192.168.1.116:7003 to 192.168.1.117:7004: ..
Moving slot 10922 from 192.168.1.116:7003 to 192.168.1.117:7004: 

查看最新分槽情况

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb info 192.168.1.117:7000 
192.168.1.117:7004 (63893e74...) -> 6683 keys | 5462 slots | 2 slaves.
192.168.1.116:7003 (c433ff1b...) -> 0 keys | 0 slots | 0 slaves.
192.168.1.117:7002 (8540a78c...) -> 6665 keys | 5461 slots | 2 slaves.
192.168.1.116:7000 (0607089e...) -> 0 keys | 0 slots | 0 slaves.
192.168.1.117:7000 (a6d7dacd...) -> 6652 keys | 5461 slots | 2 slaves.
192.168.1.116:7001 (17831f8b...) -> 0 keys | 0 slots | 0 slaves.

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb check 192.168.1.117:7000
>>> Performing Cluster Check (using node 192.168.1.117:7000)
M: a6d7dacd679a96fd79b7de552428a63610d620e6 192.168.1.117:7000
   slots:0-5460 (5461 slots) master
   2 additional replica(s)
M: 63893e74e6f8e2414eba97b094a80ae8b3caeb09 192.168.1.117:7004
   slots:5461-10922 (5462 slots) master
   2 additional replica(s)
M: 8540a78c666cb1e81fb2821d112f3040542af056 192.168.1.117:7002
   slots:10923-16383 (5461 slots) master
   2 additional replica(s)
S: 1ebeedb98619bc88bf36acbbe4a766f2f74e629f 192.168.1.117:7003
   slots: (0 slots) slave
   replicates 8540a78c666cb1e81fb2821d112f3040542af056
M: 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001
   slots: (0 slots) master
   0 additional replica(s)
S: e010d410223a2376d3308a68a724bac27ef8d74f 192.168.1.117:7001
   slots: (0 slots) slave
   replicates a6d7dacd679a96fd79b7de552428a63610d620e6
S: 17ee6bd4c68235d09acf2f4b18ae3fcc649d629c 192.168.1.116:7002
   slots: (0 slots) slave
   replicates 63893e74e6f8e2414eba97b094a80ae8b3caeb09
M: c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003
   slots: (0 slots) master
   0 additional replica(s)
S: bef4dddc01651d64b5bb3e0ac384c0eb120aa537 192.168.1.116:7004
   slots: (0 slots) slave
   replicates a6d7dacd679a96fd79b7de552428a63610d620e6
S: 2579ab004e277ba68197d851d47d0436e0cf203d 192.168.1.117:7005
   slots: (0 slots) slave
   replicates 63893e74e6f8e2414eba97b094a80ae8b3caeb09
S: fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab 192.168.1.116:7005
   slots: (0 slots) slave
   replicates 8540a78c666cb1e81fb2821d112f3040542af056
M: 0607089e5bb3192563bd8082ff230b0eb27fbfeb 192.168.1.116:7000
   slots: (0 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

验证迁移后数据

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-cli -h 192.168.1.117 -p 7000 -c dbsize
(integer) 6652
[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-cli -h 192.168.1.117 -p 7002 -c dbsize 
(integer) 6665
[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-cli -h 192.168.1.117 -p 7004 -c dbsize 
(integer) 6683


[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-cli -h 192.168.1.117 -p 7000 -c
192.168.1.117:7000> keys * 
......
6650) "name7710"
6651) "name16668"
6652) "name12290"
192.168.1.117:7000> 

迁移后从集群中删除原来的节点

查看旧集群节点地址及node id

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb check 192.168.1.117:7000 | grep 192.168.1.116
M: 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001
S: 17ee6bd4c68235d09acf2f4b18ae3fcc649d629c 192.168.1.116:7002
M: c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003
S: bef4dddc01651d64b5bb3e0ac384c0eb120aa537 192.168.1.116:7004
S: fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab 192.168.1.116:7005
M: 0607089e5bb3192563bd8082ff230b0eb27fbfeb 192.168.1.116:7000

删除旧集群中的slave节点

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb del-node 192.168.1.116:7002 17ee6bd4c68235d09acf2f4b18ae3fcc649d629c
>>> Removing node 17ee6bd4c68235d09acf2f4b18ae3fcc649d629c from cluster 192.168.1.116:7002
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb del-node 192.168.1.116:7004 bef4dddc01651d64b5bb3e0ac384c0eb120aa537
>>> Removing node bef4dddc01651d64b5bb3e0ac384c0eb120aa537 from cluster 192.168.1.116:7004
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb del-node 192.168.1.116:7005 fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab
>>> Removing node fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab from cluster 192.168.1.116:7005
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

查看删除后的节点信息

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb check 192.168.1.117:7000 | grep 192.168.1.116                       
M: 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001
M: c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003
M: 0607089e5bb3192563bd8082ff230b0eb27fbfeb 192.168.1.116:7000

删除旧集群中的master节点

删除master注意细节:
  如果还有slave节点,需要先将slave转移到其他master节点或删除slave节点
  如果master节点有slot,去掉分配的slot,然后再删除master节点。
  删除master主节点时,必须确保它上面的slot为0. 否则可能会导致整个redis cluster集群无法工作!
  如果要移除的master节点不是空的,需要先用重新分片命令来把数据移到其他的节点。

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb del-node 192.168.1.116:7000 0607089e5bb3192563bd8082ff230b0eb27fbfeb
>>> Removing node 0607089e5bb3192563bd8082ff230b0eb27fbfeb from cluster 192.168.1.116:7000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb del-node 192.168.1.116:7001 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0
>>> Removing node 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 from cluster 192.168.1.116:7001
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb del-node 192.168.1.116:7003 c433ff1b448fbcd3234632712643bc68d5213e3b
>>> Removing node c433ff1b448fbcd3234632712643bc68d5213e3b from cluster 192.168.1.116:7003
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

查看现有的节点信息

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb check 192.168.1.117:7000 
>>> Performing Cluster Check (using node 192.168.1.117:7000)
M: a6d7dacd679a96fd79b7de552428a63610d620e6 192.168.1.117:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 63893e74e6f8e2414eba97b094a80ae8b3caeb09 192.168.1.117:7004
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: 8540a78c666cb1e81fb2821d112f3040542af056 192.168.1.117:7002
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 1ebeedb98619bc88bf36acbbe4a766f2f74e629f 192.168.1.117:7003
   slots: (0 slots) slave
   replicates 8540a78c666cb1e81fb2821d112f3040542af056
S: e010d410223a2376d3308a68a724bac27ef8d74f 192.168.1.117:7001
   slots: (0 slots) slave
   replicates a6d7dacd679a96fd79b7de552428a63610d620e6
S: 2579ab004e277ba68197d851d47d0436e0cf203d 192.168.1.117:7005
   slots: (0 slots) slave
   replicates 63893e74e6f8e2414eba97b094a80ae8b3caeb09
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

[root@localhost redis-cluster]#  ./redis-4.0.6/src/redis-trib.rb info 192.168.1.117:7000      
192.168.1.117:7000 (a6d7dacd...) -> 6652 keys | 5461 slots | 1 slaves.
192.168.1.117:7004 (63893e74...) -> 6683 keys | 5462 slots | 1 slaves.
192.168.1.117:7002 (8540a78c...) -> 6665 keys | 5461 slots | 1 slaves.
[OK] 20000 keys in 3 masters.
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,185评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,652评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,524评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,339评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,387评论 6 391
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,287评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,130评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,985评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,420评论 1 313
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,617评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,779评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,477评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,088评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,716评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,857评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,876评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,700评论 2 354

推荐阅读更多精彩内容