Redis 集羣是一個提供在多個Redis間節點間共享數據的程序集。node
Redis集羣並不支持處理多個keys的命令,由於這須要在不一樣的節點間移動數據,從而達不到像Redis那樣的性能,在高負載的狀況下可能會致使不可預料的錯誤.redis
Redis 集羣經過分區來提供必定程度的可用性,在實際環境中當某個節點宕機或者不可達的狀況下繼續處理命令. Redis 集羣的優點:併發
Note that the minimal cluster that works as expected requires to contain at least three master nodes. app
由於最小的redis集羣,須要至少3個主節點,既然有3個主節點,而一個主節點搭配至少一個從節點,所以至少得6臺redis less
#環境:CentOS release 6.5
redis-5.0.5tcp
將redis解壓開裏邊的redis.conf copy出來進行改造ide
[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 <arg>
check host:port
--cluster-search-multiple-owners
info host:port
fix host:port
--cluster-search-multiple-owners
reshard host:port
--cluster-from <arg>
--cluster-to <arg>
--cluster-slots <arg>
--cluster-yes
--cluster-timeout <arg>
--cluster-pipeline <arg>
--cluster-replace
rebalance host:port
--cluster-weight <node1=w1...nodeN=wN>
--cluster-use-empty-masters
--cluster-timeout <arg>
--cluster-simulate
--cluster-pipeline <arg>
--cluster-threshold <arg>
--cluster-replace
add-node new_host:new_port existing_host:existing_port
--cluster-slave
--cluster-master-id <arg>
del-node host:port node_id
call host:port command arg arg .. arg
set-timeout host:port milliseconds
import host:port
--cluster-from <arg>
--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.ui
[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.
這個建立完了是一、三、5是master 二、四、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