• 单个redis并发有限
  • 单个redis接收所有的数据,最终回导致内存太大,内存太大回导致rdb文件过大,从很大的rdb文件中同步恢复数据会很慢。
    所。。我们需要redis cluster 即redis集群。

Redis 集群是一个提供在多个Redis间节点间共享数据的程序集。

Redis集群并不支持处理多个keys的命令,因为这需要在不同的节点间移动数据,从而达不到像Redis那样的性能,在高负载的情况下可能会导致不可预料的错误.

Redis 集群通过分区来提供一定程度的可用性,在实际环境中当某个节点宕机或者不可达的情况下继续处理命令. Redis 集群的优势:

  • 自动分割数据到不同的节点上。
  • 整个集群的部分节点失败或者不可达的情况下能够继续处理命令。
    为了配置一个redis cluster,我们需要准备至少6台redis,为啥至少6台呢?我们可以在redis的官方文档中找到如下一句话:

Note that the minimal cluster that works as expected requires to contain at least three master nodes.

因为最小的redis集群,需要至少3个主节点,既然有3个主节点,而一个主节点搭配至少一个从节点,因此至少得6台redis

#环境:CentOS release 6.5
redis-5.0.5

将redis解压开里边的redis.conf copy出来进行改造

[root@hack redis-cluster]# ps -ef |grep redis 可以查看已经起好了服务

root 2524 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7001 [cluster]
root 2529 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7002 [cluster]
root 2531 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7003 [cluster]
root 2536 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7004 [cluster]
root 2542 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7005 [cluster]
root 2546 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7006 [cluster]
root 2548 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7007 [cluster]
root 2556 1 0 19:19 ? 00:00:00 redis-server 127.0.0.1:7008 [cluster]
root 2570 2437 0 19:20 pts/3 00:00:00 grep redis

[root@hack redis-cluster]# redis-cli --cluster help 帮助说明
Cluster Manager Commands:
create host1:port1 ... hostN:portN
--cluster-replicas
check host:port
--cluster-search-multiple-owners
info host:port
fix host:port
--cluster-search-multiple-owners
reshard host:port
--cluster-from
--cluster-to
--cluster-slots
--cluster-yes
--cluster-timeout
--cluster-pipeline
--cluster-replace
rebalance host:port
--cluster-weight
--cluster-use-empty-masters
--cluster-timeout
--cluster-simulate
--cluster-pipeline
--cluster-threshold
--cluster-replace
add-node new_host:new_port existing_host:existing_port
--cluster-slave
--cluster-master-id
del-node host:port node_id
call host:port command arg arg .. arg
set-timeout host:port milliseconds
import host:port
--cluster-from
--cluster-copy
--cluster-replace
help

For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

[root@hack redis-cluster]#创建redis-cluster

[root@hack redis-cluster]# redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7003 127.0.0.1:7005 127.0.0.1:7002 127.0.0.1:7004 127.0.0.1:7006 --cluster-replicas 1 Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7006 to 127.0.0.1:7003
Adding replica 127.0.0.1:7002 to 127.0.0.1:7005Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5461-10922] (5462 slots) master
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[10923-16383] (5461 slots) master
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
replicates 0cb13608e635ce2fed09baf9af28af382fc899ae
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
S: 7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
Can I set the above configuration? (type 'yes' to accept): yes

这里说明一下5.0.5会随即将的选择主备 不同意直接退出 你可以调整创建时节点的位置进行调整

Nodes configuration updated
Assign a different config epoch to each node
Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.....
Performing Cluster Check (using node 127.0.0.1:7001)
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
13822893552553689089 additional replica(s)
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
slots: (0 slots) slave
replicates 0cb13608e635ce2fed09baf9af28af382fc899ae
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5461-10922] (5462 slots) master
636536182154461185 additional replica(s)
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[10923-16383] (5461 slots) master
636536319593414657 additional replica(s)
S: 7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006
slots: (0 slots) slave
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.

这个创建完了是1、3、5是master 2、4、6是slave 具体哪个master-slave 根据node-ID对应

[root@hack redis-cluster]# redis-cli -p 7001

连接到集群的任意一个节点执行这个命令都可以看到信息

127.0.0.1:7001> CLUSTER NODES
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 slave 0cb13608e635ce2fed09baf9af28af382fc899ae 0 1567682526000 4 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567682527608 5 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567682526000 2 connected 5461-10922
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 master - 0 1567682526577 3 connected 10923-16383
7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006@17006 slave 02dd339481db475dfa3cf520f5386ee188f1ed89 0 1567682525568 6 connected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567682525000 1 connected 0-5460
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 0 keys | 5461 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.

[root@hack redis-cluster]# redis-cli --cluster add-node 127.0.0.1:7007 127.0.0.1:7001 新增一个节点,没有参数就是主节点,这个时候还是一个空的节点,应用不会往这个slot写东西

Adding node 127.0.0.1:7007 to cluster 127.0.0.1:7001
Performing Cluster Check (using node 127.0.0.1:7001)
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
13809787786267459585 additional replica(s)
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
slots: (0 slots) slave
replicates 0cb13608e635ce2fed09baf9af28af382fc899ae
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5461-10922] (5462 slots) master
679412600152260609 additional replica(s)
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[10923-16383] (5461 slots) master
679412943749644289 additional replica(s)
S: 7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006
slots: (0 slots) slave
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
Send CLUSTER MEET to node 127.0.0.1:7007 to make it join the cluster.
[OK] New node added correctly.
[root@hack redis-cluster]# redis-cli -p 7001
127.0.0.1:7001> cluster nodes
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 slave 0cb13608e635ce2fed09baf9af28af382fc899ae 0 1567682647631 4 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567682646619 5 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567682646000 2 connected 5461-10922
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 master - 0 1567682645608 3 connected 10923-16383
7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006@17006 slave 02dd339481db475dfa3cf520f5386ee188f1ed89 0 1567682648685 6 connected
c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007@17007 master - 0 1567682645000 0 connected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567682647000 1 connected 0-5460
127.0.0.1:7001> quit

[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
可以看到7007节点还是0个slot

127.0.0.1:7001 (9c8df716...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5462 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 0 keys | 5461 slots | 1 slaves.
127.0.0.1:7007 (c94c7bba...) -> 0 keys | 0 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# redis-cli --cluster reshard 127.0.0.1:7001 --cluster-from 9c8df71622d469741a2b208c4eeda96c8660e867,0cb13608e635ce2fed09baf9af28af382fc899ae,02dd339481db475dfa3cf520f5386ee188f1ed89 --cluster-to c94c7bba62ee3da3037f5b29a2fe8431122fc902 --cluster-slots 1200 --cluster-yes
Performing Cluster Check (using node 127.0.0.1:7001)

连接到集群的任意节点,给新增的节点分配1200个slot

M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
13822154118099107841 additional replica(s)
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
slots: (0 slots) slave
replicates 0cb13608e635ce2fed09baf9af28af382fc899ae
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5461-10922] (5462 slots) master
657528367389605889 additional replica(s)
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[10923-16383] (5461 slots) master
657528710986989569 additional replica(s)
S: 7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006
slots: (0 slots) slave
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
M: c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007
slots: (0 slots) master
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.

Ready to move 1200 slots.
Source nodes:
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5460] (5461 slots) master
13822154118099107841 additional replica(s)
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[10923-16383] (5461 slots) master
657528710986989569 additional replica(s)
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5461-10922] (5462 slots) master
657528367389605889 additional replica(s)
Destination node:
M: c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007
slots: (0 slots) master
Resharding plan:
Moving slot 5461 from 02dd339481db475dfa3cf520f5386ee188f1ed89
Moving slot 5462 from 02dd339481db475dfa3cf520f5386ee188f1ed89
Moving slot 5463 from 02dd339481db475dfa3cf520f5386ee188f1ed89
。。。。
Moving slot 5861 from 02dd339481db475dfa3cf520f5386ee188f1ed89
Moving slot 0 from 9c8df71622d469741a2b208c4eeda96c8660e867
Moving slot 1 from 9c8df71622d469741a2b208c4eeda96c8660e867
。。。。
Moving slot 397 from 9c8df71622d469741a2b208c4eeda96c8660e867
Moving slot 398 from 9c8df71622d469741a2b208c4eeda96c8660e867
Moving slot 10923 from 0cb13608e635ce2fed09baf9af28af382fc899ae
Moving slot 10924 from 0cb13608e635ce2fed09baf9af28af382fc899ae
。。。。
Moving slot 11321 from 0cb13608e635ce2fed09baf9af28af382fc899ae
Moving slot 5461 from 127.0.0.1:7003 to 127.0.0.1:7007:
Moving slot 5462 from 127.0.0.1:7003 to 127.0.0.1:7007:
。。。。
Moving slot 5860 from 127.0.0.1:7003 to 127.0.0.1:7007:
Moving slot 5861 from 127.0.0.1:7003 to 127.0.0.1:7007:
Moving slot 0 from 127.0.0.1:7001 to 127.0.0.1:7007:
Moving slot 1 from 127.0.0.1:7001 to 127.0.0.1:7007:
Moving slot 2 from 127.0.0.1:7001 to 127.0.0.1:7007:
。。。。
Moving slot 397 from 127.0.0.1:7001 to 127.0.0.1:7007:
Moving slot 398 from 127.0.0.1:7001 to 127.0.0.1:7007:
Moving slot 10923 from 127.0.0.1:7005 to 127.0.0.1:7007:
Moving slot 10924 from 127.0.0.1:7005 to 127.0.0.1:7007:
Moving slot 10925 from 127.0.0.1:7005 to 127.0.0.1:7007:
。。。。
Moving slot 11320 from 127.0.0.1:7005 to 127.0.0.1:7007:
Moving slot 11321 from 127.0.0.1:7005 to 127.0.0.1:7007:

[root@hack redis-cluster]# redis-cli -p 7001 可以看到分配的slots

127.0.0.1:7001> cluster nodes
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 slave 0cb13608e635ce2fed09baf9af28af382fc899ae 0 1567682792209 4 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567682793000 5 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567682794225 2 connected 5862-10922
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 master - 0 1567682793218 3 connected 11322-16383
7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006@17006 slave 02dd339481db475dfa3cf520f5386ee188f1ed89 0 1567682791201 6 connected
c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007@17007 master - 0 1567682790000 7 connected 0-398 5461-5861 10923-11321
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567682791000 1 connected 399-5460
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001 可以看到分配的slots
127.0.0.1:7001 (9c8df716...) -> 0 keys | 5062 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 0 keys | 5062 slots | 1 slaves.
127.0.0.1:7007 (c94c7bba...) -> 0 keys | 1199 slots | 0 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.

[root@hack redis-cluster]#新增一个slave节点

[root@hack redis-cluster]# redis-cli --cluster add-node 127.0.0.1:7008 127.0.0.1:7007 --cluster-slave --cluster-master-id c94c7bba62ee3da3037f5b29a2fe8431122fc902
Adding node 127.0.0.1:7008 to cluster 127.0.0.1:7007
Performing Cluster Check (using node 127.0.0.1:7007)
M: c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007
slots:[0-398],[5461-5861],[10923-11321] (1199 slots) master
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
slots: (0 slots) slave
replicates 0cb13608e635ce2fed09baf9af28af382fc899ae
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[11322-16383] (5062 slots) master
718660629778399233 additional replica(s)
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[399-5460] (5062 slots) master
718660973375782913 additional replica(s)
S: 7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006
slots: (0 slots) slave
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
718661866728980481 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
Send CLUSTER MEET to node 127.0.0.1:7008 to make it join the cluster.
Waiting for the cluster to join

Configure node as replica of 127.0.0.1:7007.
[OK] New node added correctly.
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 0 keys | 5062 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 0 keys | 5062 slots | 1 slaves.
127.0.0.1:7007 (c94c7bba...) -> 0 keys | 1199 slots | 1 slaves.
[OK] 0 keys in 4 masters.
0.00 keys per slot on average.

[root@hack redis-cluster]# redis-cli -p 7001 加上键值后续测试删除用,后续删除的时候发现删除提示nodes不为空

127.0.0.1:7001> set foo 123
(error) MOVED 12182 127.0.0.1:7005
127.0.0.1:7001> set bar 456
OK
127.0.0.1:7001> set hack 789
(error) MOVED 13310 127.0.0.1:7005
127.0.0.1:7001> keys
1) "bar"
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli -p 7005
127.0.0.1:7005> keys

(empty list or set)
127.0.0.1:7005> set hack 789
OK
127.0.0.1:7005> set foo 123
OK
127.0.0.1:7005> quit
[root@hack redis-cluster]# redis-cli -p 7006
127.0.0.1:7006> keys *
(empty list or set)

[root@hack redis-cluster]# redis-cli --cluster add-node 127.0.0.1:7010 127.0.0.1:7007 --cluster-slave --cluster-master-id c94c7bba62ee3da3037f5b29a2fe8431122fc902
Adding node 127.0.0.1:7010 to cluster 127.0.0.1:7007
Performing Cluster Check (using node 127.0.0.1:7007)
M: c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007
slots:[0-398],[5461-5861],[10923-11321] (1199 slots) master
13815628061321723905 additional replica(s)
S: 60e500b0bd929b6922e24fbc8a0c42cf04c0932d 127.0.0.1:7008
slots: (0 slots) slave
replicates c94c7bba62ee3da3037f5b29a2fe8431122fc902
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
slots: (0 slots) slave
replicates 0cb13608e635ce2fed09baf9af28af382fc899ae
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[11322-16383] (5062 slots) master
716621757263380481 additional replica(s)
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[399-5460] (5062 slots) master
716622100860764161 additional replica(s)
S: 7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006
slots: (0 slots) slave
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
716622994213961729 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
Send CLUSTER MEET to node 127.0.0.1:7010 to make it join the cluster.
Waiting for the cluster to join

Configure node as replica of 127.0.0.1:7007.
[OK] New node added correctly.
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 1 keys | 5062 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 2 keys | 5062 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 1 slaves.
127.0.0.1:7007 (c94c7bba...) -> 0 keys | 1199 slots | 2 slaves.
[OK] 3 keys in 4 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# redis-cli -p 7003
127.0.0.1:7003> CLUSTER nodes
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 slave 0cb13608e635ce2fed09baf9af28af382fc899ae 0 1567683177628 4 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567683177000 5 connected
c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007@17007 master - 0 1567683176000 7 connected 0-398 5461-5861 10923-11321
7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006@17006 slave 02dd339481db475dfa3cf520f5386ee188f1ed89 0 1567683176621 6 connected
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 master - 0 1567683178000 3 connected 11322-16383
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 myself,master - 0 1567683176000 2 connected 5862-10922
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 master - 0 1567683174601 1 connected 399-5460
1539a4471e10c6685b1fe43bbf8bf52baa160019 127.0.0.1:7010@17010 slave c94c7bba62ee3da3037f5b29a2fe8431122fc902 0 1567683178635 7 connected
60e500b0bd929b6922e24fbc8a0c42cf04c0932d 127.0.0.1:7008@17008 slave c94c7bba62ee3da3037f5b29a2fe8431122fc902 0 1567683179645 7 connected
127.0.0.1:7003> quit
[root@hack redis-cluster]# redis-cli -p 7007
127.0.0.1:7007> hset a var 1
(error) MOVED 15495 127.0.0.1:7005
127.0.0.1:7007> set 1 1
(error) MOVED 9842 127.0.0.1:7003
127.0.0.1:7007> set 100 1
OK
127.0.0.1:7007> keys
1) "100"
127.0.0.1:7007> quit
[root@hack redis-cluster]# redis-cli -p 7010
127.0.0.1:7010> keys

1) "100"
127.0.0.1:7010> quit
[root@hack redis-cluster]#

[root@hack redis-cluster]# 删除的时候肯定是先删除slave,然后在删除master

[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7010 1539a4471e10c6685b1fe43bbf8bf52baa160019
Removing node 1539a4471e10c6685b1fe43bbf8bf52baa160019 from cluster 127.0.0.1:7010
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7008 60e500b0bd929b6922e24fbc8a0c42cf04c0932d
Removing node 60e500b0bd929b6922e24fbc8a0c42cf04c0932d from cluster 127.0.0.1:7008
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7007 c94c7bba62ee3da3037f5b29a2fe8431122fc902
Removing node c94c7bba62ee3da3037f5b29a2fe8431122fc902 from cluster 127.0.0.1:7007
[ERR] Node 127.0.0.1:7007 is not empty! Reshard data away and try again.

root@hack redis-cluster]#由于7007这个还有slots需要先调整到其他节点

[root@hack redis-cluster]# redis-cli --cluster reshard 127.0.0.1:7001 --cluster-from c94c7bba62ee3da3037f5b29a2fe8431122fc902 --cluster-to 9c8df71622d469741a2b208c4eeda96c8660e867 --cluster-slots 1200 --cluster-yes
Performing Cluster Check (using node 127.0.0.1:7001)
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[399-5460] (5062 slots) master
13831865356982943745 additional replica(s)
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[11322-16383] (5062 slots) master
704534516701593601 additional replica(s)
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
slots: (0 slots) slave
replicates 0cb13608e635ce2fed09baf9af28af382fc899ae
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
704570663146356737 additional replica(s)
S: 7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006
slots: (0 slots) slave
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
M: c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007
slots:[0-398],[5461-5861],[10923-11321] (1199 slots) master
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.

Ready to move 1200 slots.
Source nodes:
M: c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007
slots:[0-398],[5461-5861],[10923-11321] (1199 slots) master
Destination node:
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[399-5460] (5062 slots) master
13831865356982943745 additional replica(s)
Resharding plan:
Moving slot 0 from c94c7bba62ee3da3037f5b29a2fe8431122fc902
。。。。
Moving slot 11320 from c94c7bba62ee3da3037f5b29a2fe8431122fc902
Moving slot 11321 from c94c7bba62ee3da3037f5b29a2fe8431122fc902
Moving slot 0 from 127.0.0.1:7007 to 127.0.0.1:7001:
。。。。
Moving slot 11321 from 127.0.0.1:7007 to 127.0.0.1:7001:
[root@hack redis-cluster]# redis-cli -p 7001
127.0.0.1:7001> cluster nodes
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 master - 0 1567683759297 3 connected 11322-16383
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567683755000 8 connected
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 slave 0cb13608e635ce2fed09baf9af28af382fc899ae 0 1567683756271 4 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567683758000 2 connected 5862-10922
7c86270badac849253c2348fe924884595abd991 127.0.0.1:7006@17006 slave 02dd339481db475dfa3cf520f5386ee188f1ed89 0 1567683758288 6 connected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567683756000 8 connected 0-5861 10923-11321
c94c7bba62ee3da3037f5b29a2fe8431122fc902 127.0.0.1:7007@17007 master - 0 1567683756000 7 connected
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 2 keys | 6261 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 2 keys | 5062 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 1 slaves.
127.0.0.1:7007 (c94c7bba...) -> 0 keys | 0 slots | 0 slaves.
[OK] 4 keys in 4 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# redis-cli -p 7001
127.0.0.1:7001> CLUSTER REPLICAS 9c8df71622d469741a2b208c4eeda96c8660e867
1) "35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567683874493 8 connected"
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli -p 7007
127.0.0.1:7007> keys *
(empty list or set)
127.0.0.1:7007> quit
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7007 c94c7bba62ee3da3037f5b29a2fe8431122fc902
Removing node c94c7bba62ee3da3037f5b29a2fe8431122fc902 from cluster 127.0.0.1:7007
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.

[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001可以看到已经删除了一个master

127.0.0.1:7001 (9c8df716...) -> 2 keys | 6261 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 2 keys | 5062 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 1 slaves.
[OK] 4 keys in 3 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7003 02dd339481db475dfa3cf520f5386ee188f1ed89
Removing node 02dd339481db475dfa3cf520f5386ee188f1ed89 from cluster 127.0.0.1:7003
[ERR] Node 127.0.0.1:7003 is not empty! Reshard data away and try again.
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7006 7c86270badac849253c2348fe924884595abd991
Removing node 7c86270badac849253c2348fe924884595abd991 from cluster 127.0.0.1:7006
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7003 02dd339481db475dfa3cf520f5386ee188f1ed89
Removing node 02dd339481db475dfa3cf520f5386ee188f1ed89 from cluster 127.0.0.1:7003
[ERR] Node 127.0.0.1:7003 is not empty! Reshard data away and try again.
[root@hack redis-cluster]#
[root@hack redis-cluster]#
[root@hack redis-cluster]#
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7002 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad
Removing node 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad from cluster 127.0.0.1:7002
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 2 keys | 6261 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 2 keys | 5062 slots | 0 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 0 slaves.
[OK] 4 keys in 3 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# redis-cli --cluster nodes 127.0.0.1:7001
Unknown --cluster subcommand
[root@hack redis-cluster]# redis-cli -p 7001
127.0.0.1:7001> cluster nodes
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 master - 0 1567684128138 3 connected 11322-16383
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567684130153 8 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567684129147 2 connected 5862-10922
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567684127000 8 connected 0-5861 10923-11321
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli -p 7005
127.0.0.1:7005> keys *
1) "hack"
2) "foo"
127.0.0.1:7005> quit
[root@hack redis-cluster]# redis-cli -p 7005
127.0.0.1:7005> save
OK
127.0.0.1:7005> quit
[root@hack redis-cluster]# redis-cli --cluster reshard 127.0.0.1:7001 --cluster-from 0cb13608e635ce2fed09baf9af28af382fc899ae --cluster-to 9c8df71622d469741a2b208c4eed[root@hack redis-cluster]# redis-cli --cluster reshard 127.0.0.1:7001 --cluster-from 0cb13608e635ce2fed09baf9af28af382fc899ae --cluster-to 9c8df71622d469741a2b208c4eeda96c8660e867 --cluster-slots 5062 --cluster-yes
Performing Cluster Check (using node 127.0.0.1:7001)
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5861],[10923-11321] (6261 slots) master
13810948247776133121 additional replica(s)
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[11322-16383] (5062 slots) master
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.

Ready to move 5062 slots.
Source nodes:
M: 0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005
slots:[11322-16383] (5062 slots) master
Destination node:
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5861],[10923-11321] (6261 slots) master
13810948247776133121 additional replica(s)
Resharding plan:
Moving slot 11322 from 0cb13608e635ce2fed09baf9af28af382fc899ae
Moving slot 11323 from 0cb13608e635ce2fed09baf9af28af382fc899ae
....
Moving slot 16381 from 127.0.0.1:7005 to 127.0.0.1:7001:
Moving slot 16382 from 127.0.0.1:7005 to 127.0.0.1:7001:
Moving slot 16383 from 127.0.0.1:7005 to 127.0.0.1:7001:
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 4 keys | 11323 slots | 1 slaves.
127.0.0.1:7005 (0cb13608...) -> 0 keys | 0 slots | 0 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 0 slaves.
[OK] 4 keys in 3 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# redis-cli -p 7005
127.0.0.1:7005> cluster nodes
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567684289111 8 connected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 master - 0 1567684291193 8 connected 0-5861 10923-16383
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 myself,master - 0 1567684290000 3 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567684290183 2 connected 5862-10922
127.0.0.1:7005> quit
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7005 0cb13608e635ce2fed09baf9af28af382fc899ae
Removing node 0cb13608e635ce2fed09baf9af28af382fc899ae from cluster 127.0.0.1:7005
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 4 keys | 11323 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 0 slaves.
[OK] 4 keys in 2 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# ps -ef |grep redis
root 2524 1 0 19:19 ? 00:00:10 redis-server 127.0.0.1:7001 [cluster]
root 2531 1 0 19:19 ? 00:00:07 redis-server 127.0.0.1:7003 [cluster]
root 2536 1 0 19:19 ? 00:00:03 redis-server 127.0.0.1:7004 [cluster]
root 2662 2437 0 19:52 pts/3 00:00:00 grep redis

[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 4 keys | 11323 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 0 slaves.
[OK] 4 keys in 2 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]#
[root@hack redis-cluster]# redis-cli -p 7001
127.0.0.1:7001> cluster nodes
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567684978427 8 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567684979437 2 connected 5862-10922
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567684977000 8 connected 0-5861 10923-16383
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli --cluster add-node 127.0.0.1:7004 127.0.0.1:7003 --cluster-slave --cluster-master-id 02dd339481db475dfa3cf520f5386ee188f1ed89
Adding node 127.0.0.1:7004 to cluster 127.0.0.1:7003
Performing Cluster Check (using node 127.0.0.1:7003)
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5861],[10923-16383] (11323 slots) master
583902835410731009 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
[ERR] Node 127.0.0.1:7004 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

[root@hack redis-cluster]# redis-cli -p 7002
127.0.0.1:7002> cluster nodes
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567685223214 2 connected 5862-10922
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 myself,slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567685049391 4 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567685222205 8 connected
0cb13608e635ce2fed09baf9af28af382fc899ae 127.0.0.1:7005@17005 master,fail? - 1567685049396 1567685049391 3 disconnected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 master - 0 1567685222000 8 connected 0-5861 10923-16383
127.0.0.1:7002> cluster reset
OK
127.0.0.1:7002> cluster nodes
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 myself,master - 0 1567685049391 4 connected
127.0.0.1:7002> quit
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7002 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad
Removing node 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad from cluster 127.0.0.1:7002
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.

[root@hack redis-cluster]# rm -rf dump.rdb appendonly.aof 这个就是新加节点到集群的时候报错的原因

[root@hack redis-cluster]# redis-server 7002.conf
[root@hack redis-cluster]# redis-cli --cluster add-node 127.0.0.1:7002 127.0.0.1:7003 --cluster-slave --cluster-master-id 02dd339481db475dfa3cf520f5386ee188f1ed89
Adding node 127.0.0.1:7002 to cluster 127.0.0.1:7003
Performing Cluster Check (using node 127.0.0.1:7003)
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5861],[10923-16383] (11323 slots) master
603869966571143169 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.
Send CLUSTER MEET to node 127.0.0.1:7002 to make it join the cluster.
Waiting for the cluster to join

Configure node as replica of 127.0.0.1:7003.
[OK] New node added correctly.
[root@hack redis-cluster]# redis-cli -p 7002
127.0.0.1:7002> cluster nodes
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 myself,slave 02dd339481db475dfa3cf520f5386ee188f1ed89 0 1567685286000 4 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567685287000 8 connected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 master - 0 1567685287877 8 connected 0-5861 10923-16383
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567685287000 2 connected 5862-10922
127.0.0.1:7002> quit
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 4 keys | 11323 slots | 1 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 5061 slots | 1 slaves.
[OK] 4 keys in 2 masters.
0.00 keys per slot on average.

测试如果报master的slots分配到别的地方去,slave会怎么抉择

[root@hack redis-cluster]# redis-cli --cluster reshard 127.0.0.1:7001 --cluster-from 02dd339481db475dfa3cf520f5386ee188f1ed89 --cluster-to 9c8df71622d469741a2b208c4eeda96c8660e867 --cluster-slots 5061 --cluster-yes
Performing Cluster Check (using node 127.0.0.1:7001)
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5861],[10923-16383] (11323 slots) master
13808168622251573249 additional replica(s)
S: 0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002
slots: (0 slots) slave
replicates 02dd339481db475dfa3cf520f5386ee188f1ed89
S: 35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004
slots: (0 slots) slave
replicates 9c8df71622d469741a2b208c4eeda96c8660e867
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
678039825525243905 additional replica(s)
[OK] All nodes agree about slots configuration.
Check for open slots...
Check slots coverage...
[OK] All 16384 slots covered.

Ready to move 5061 slots.
Source nodes:
M: 02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003
slots:[5862-10922] (5061 slots) master
678039825525243905 additional replica(s)
Destination node:
M: 9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001
slots:[0-5861],[10923-16383] (11323 slots) master
13808168622251573249 additional replica(s)
Resharding plan:
Moving slot 5862 from 02dd339481db475dfa3cf520f5386ee188f1ed89
Moving slot 5863 from 02dd339481db475dfa3cf520f5386ee188f1ed89
。。。。
Moving slot 10922 from 127.0.0.1:7003 to 127.0.0.1:7001:
[root@hack redis-cluster]# redis-cli --cluster info 127.0.0.1:7001
127.0.0.1:7001 (9c8df716...) -> 4 keys | 16384 slots | 2 slaves.
127.0.0.1:7003 (02dd3394...) -> 0 keys | 0 slots | 0 slaves.
[OK] 4 keys in 2 masters.
0.00 keys per slot on average.
[root@hack redis-cluster]# redis-cli -p 7001
127.0.0.1:7001> cluster nodes
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567685422000 8 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567685420000 8 connected
02dd339481db475dfa3cf520f5386ee188f1ed89 127.0.0.1:7003@17003 master - 0 1567685422866 2 connected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567685421000 8 connected 0-16383
127.0.0.1:7001> quit
[root@hack redis-cluster]# redis-cli --cluster del-node 127.0.0.1:7003 02dd339481db475dfa3cf520f5386ee188f1ed89
Removing node 02dd339481db475dfa3cf520f5386ee188f1ed89 from cluster 127.0.0.1:7003
Sending CLUSTER FORGET messages to the cluster...
SHUTDOWN the node.

[root@hack redis-cluster]# redis-cli -p 7001 可以看到master的slots分走之后,slave自动的切换到剩余的master里边

127.0.0.1:7001> cluster nodes
0d2bce412514e7f6c4fbd0e8b12f2c28940bbcad 127.0.0.1:7002@17002 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567685464303 8 connected
35d3a9d195d9d9978a66ad2c1f25e30bf3796030 127.0.0.1:7004@17004 slave 9c8df71622d469741a2b208c4eeda96c8660e867 0 1567685465331 8 connected
9c8df71622d469741a2b208c4eeda96c8660e867 127.0.0.1:7001@17001 myself,master - 0 1567685461000 8 connected 0-16383
127.0.0.1:7001> quit

附件7001.conf
bind 127.0.0.1
protected-mode yes
port 7001
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_7001.pid
loglevel notice
logfile "./7001.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes


用到命令 flushdb
cluster reset
save
cankao:https://blog.csdn.net/qq1137623160/article/details/79184686