现有环境

实验背景:

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.

linux redis 数据迁移,redis cluster 迁移数据相关推荐

  1. redis 3.0 集群__数据迁移和伸缩容

    添加节点 1,启动2个新的redis-sever, 参照 ( redis 3.0 集群____安装 ),端口号为 7007 和 7008 2,使用命令 redis-trib.rb add-node 命 ...

  2. 把oracle数据导入redis,Oracle向redis数据迁移

    将Oracle一张配置表数据迁移至redis,来减少频繁的数据库查询带来的开销. RESP协议 Redis的协议规范(Redis Protocol specification) 在Redis 2.0中 ...

  3. php实现mysql 数据迁移_php实现redis数据库指定库号迁移的方法

    本文实例讲述了php实现redis数据库指定库号迁移的方法,分享给大家供大家参考.具体如下: redis普通的数据库迁移,只能整个redis save,或者利用主从,当然也可以安装一个redis-du ...

  4. Linux企业化运维--(7)redis服务之redis配置及主从复制、主从自动切换、集群、redis+mysql、gearman实现数据同步

    Linux企业化运维 实验所用系统为Redhat-rhel7.6. 目录 Linux企业化运维 Linux企业化运维--(7)redis服务之redis配置及主从复制.主从自动切换.集群.redis+ ...

  5. Linux系统InfluxDB数据和日志目录迁移教程

    前言: 生产环境上,InfluDB数据存储所在磁盘即将无存储空间时,需要将数据迁移到更大的磁盘,或者机械硬盘更换固态硬盘时,都需要迁移旧数据,本文将介绍InfluxDB v1.8.x版本的数据迁移方法 ...

  6. Redis 缓存数据库使用 Redis-Shake 做数据同步

    目录 Redis 缓存数据库使用 Redis-Shake 做数据同步 Redis-shake 简介 Redis-Shake 同步的五种模式 基本原理 部署过程 同步模式 restore 模式 dump ...

  7. 大数据系列——Redis理论

    概述 Remote Dictionary Server(Redis) 是一个由 Salvatore Sanfilippo写的 key-value存储系统,是跨平台的非关系型数据库,也属于一种nosql ...

  8. 教育启蒙赛道、亿级异构数据不停服平滑迁移方案和实践

    背景 学前启蒙教育赛道,竞争日益激励,好未来集团旗下"小猴英语","小猴语文","小猴思维"三条独立产品站线,战略调整,资源合并,重拳出击, ...

  9. Spring Boot实战解决高并发数据入库: Redis 缓存+MySQL 批量入库

    前言 最近在做阅读类的业务,需要记录用户的PV,UV: 项目状况:前期尝试业务阶段: 特点: 快速实现(不需要做太重,满足初期推广运营即可) 快速投入市场去运营 收集用户的原始数据,三要素: 谁 在什 ...

  10. GitLab默认仓库存储目录更换及项目迁移 GitLab跨服务器数据迁移

    一.GitLab的数据从旧服务器迁移到新服务器 注释:旧服务器.新服务器GitLab版本保持一致,如果不一致得需要升级 1旧服务器上的安装版本 [root@iZbp1ac9uozodszcdkd98n ...

最新文章

  1. HBase的安装、写入和查询操作
  2. Google开源word2vec,文本相似度计算工具
  3. 人脸识别技术大总结(1):Face Detection Alignment
  4. 探索startActivity流程及在Activity间是如何传递Intent的
  5. 团队项目(NABC分析)
  6. php 自定义打印模板下载,PHP – 创建自定义模板系统?
  7. excel统计行数_百万到亿级数据,快速统计查询
  8. nginx学习笔记003---Nginx代理配置_注意,在Windows中路径要用/
  9. 数据结构与算法之-----总览
  10. php中money用什么显示,如何使用PHP将十进制数转换为单词(money格式)?
  11. [AutoSAR]NXP HS12(X) AUTOSAR MCAL编译一下
  12. LOJ2001 SDOI2017 树点涂色 LCT、线段树
  13. LightOj 1088 - Points in Segments (二分枚举)
  14. 最强抓包神器 Fiddler 手机抓包详解
  15. 运维学习:常用运维工具
  16. 财务软件虚拟服务器,新中大财务软件远程虚拟化办公方案
  17. windows python3.6 tensorflow1.12搭建RCNN运行环境 bug解决
  18. Blender新手入门试水作品:Low poly版敲击兽
  19. ICSharpCode.SharpZipLib压缩解压
  20. CF终于上紫了。。。

热门文章

  1. CUDA编译器nvcc的用法用例与问题简答
  2. vue 打包后本地先自己启动服务 anywhere 非常好用
  3. 【CF666E】Forensic Examination - 广义后缀自动机+线段树合并
  4. ubantu系统之快捷键使用
  5. 电子开发网---一个硬件很好的网站
  6. oracle decode函数
  7. 【Data guard】SWITCHOVER_STATUS为FAILED DESTINATION解决办法
  8. Ubuntu18.04中配置QT5.11开发环境
  9. kernel笔记——库文件与系统调用
  10. 64. 合并排序数组 II