为了账号安全,请及时绑定邮箱和手机立即绑定

redis cluster 迁移数据

标签:
Redis

现有环境

实验背景:

  • 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/bashfor ((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 + 668320000

查看旧集群信息

旧集群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 connected17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001@17001 master - 0 1545035374876 3 connected 10923-1638317ee6bd4c68235d09acf2f4b18ae3fcc649d629c 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-109220607089e5bb3192563bd8082ff230b0eb27fbfeb 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 nodesbef4dddc01651d64b5bb3e0ac384c0eb120aa537 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-1092217ee6bd4c68235d09acf2f4b18ae3fcc649d629c 192.168.1.116:7002@17002 slave c433ff1b448fbcd3234632712643bc68d5213e3b 0 1545036232000 5 connected
a6d7dacd679a96fd79b7de552428a63610d620e6 192.168.1.117:7000@17000 master - 0 1545036236960 0 connected2579ab004e277ba68197d851d47d0436e0cf203d 192.168.1.117:7005@17005 slave 63893e74e6f8e2414eba97b094a80ae8b3caeb09 0 1545036233955 8 connected
e010d410223a2376d3308a68a724bac27ef8d74f 192.168.1.117:7001@17001 slave a6d7dacd679a96fd79b7de552428a63610d620e6 0 1545036235958 0 connected63893e74e6f8e2414eba97b094a80ae8b3caeb09 192.168.1.117:7004@17004 master - 0 1545036234000 8 connected17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001@17001 master - 0 1545036234957 3 connected 10923-163838540a78c666cb1e81fb2821d112f3040542af056 192.168.1.117:7002@17002 master - 0 1545036233000 7 connected1ebeedb98619bc88bf36acbbe4a766f2f74e629f 192.168.1.117:7003@17003 slave 8540a78c666cb1e81fb2821d112f3040542af056 0 1545036231952 7 connected0607089e5bb3192563bd8082ff230b0eb27fbfeb 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 infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:12cluster_size:3cluster_current_epoch:10cluster_my_epoch:1cluster_stats_messages_ping_sent:19905cluster_stats_messages_pong_sent:21355cluster_stats_messages_sent:41260cluster_stats_messages_ping_received:21344cluster_stats_messages_pong_received:19905cluster_stats_messages_meet_received:11cluster_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 masterc433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003@17003 master - 0 1545036369126 2 connected 5461-10922a6d7dacd679a96fd79b7de552428a63610d620e6 192.168.1.117:7000@17000 master - 0 1545036371000 0 connected63893e74e6f8e2414eba97b094a80ae8b3caeb09 192.168.1.117:7004@17004 master - 0 1545036371000 8 connected17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001@17001 master - 0 1545036371130 3 connected 10923-163838540a78c666cb1e81fb2821d112f3040542af056 192.168.1.117:7002@17002 master - 0 1545036373133 7 connected0607089e5bb3192563bd8082ff230b0eb27fbfeb 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:7000192.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:7000How many slots do you want to move (from 1 to 16384)? 5461      # 分配多少数量的slotWhat 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:doneDo 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 7000192.168.1.117:7000> cluster setslot 0 stable  #The following slots are open: 0 这里是多少就写多少OK192.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 这里是多少就写多少OK192.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:7000How many slots do you want to move (from 1 to 16384)? 5461      # 分配多少数量的slotWhat 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:doneDo 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:7002How 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:17831f8bbcd43ac05efc5486ebfcdbb210ce48f0Source 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:7004How 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:c433ff1b448fbcd3234632712643bc68d5213e3bSource 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 8540a78c666cb1e81fb2821d112f3040542af056M: 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 a6d7dacd679a96fd79b7de552428a63610d620e6S: 17ee6bd4c68235d09acf2f4b18ae3fcc649d629c 192.168.1.116:7002
   slots: (0 slots) slave
   replicates 63893e74e6f8e2414eba97b094a80ae8b3caeb09M: 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 a6d7dacd679a96fd79b7de552428a63610d620e6S: 2579ab004e277ba68197d851d47d0436e0cf203d 192.168.1.117:7005
   slots: (0 slots) slave
   replicates 63893e74e6f8e2414eba97b094a80ae8b3caeb09S: fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab 192.168.1.116:7005
   slots: (0 slots) slave
   replicates 8540a78c666cb1e81fb2821d112f3040542af056M: 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 -c192.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.116M: 17831f8bbcd43ac05efc5486ebfcdbb210ce48f0 192.168.1.116:7001S: 17ee6bd4c68235d09acf2f4b18ae3fcc649d629c 192.168.1.116:7002M: c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003S: bef4dddc01651d64b5bb3e0ac384c0eb120aa537 192.168.1.116:7004S: fb8dc97c90f3edc7f10a385f4b4b2a2b2612ffab 192.168.1.116:7005M: 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:7001M: c433ff1b448fbcd3234632712643bc68d5213e3b 192.168.1.116:7003M: 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 8540a78c666cb1e81fb2821d112f3040542af056S: e010d410223a2376d3308a68a724bac27ef8d74f 192.168.1.117:7001
   slots: (0 slots) slave
   replicates a6d7dacd679a96fd79b7de552428a63610d620e6S: 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.



作者:baiyongjie
链接:https://www.jianshu.com/p/925f69f2fc35


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
手记
粉丝
201
获赞与收藏
871

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消