linux redis 数据迁移,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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值