主頁(yè) > 知識(shí)庫(kù) > Redis Cluster添加、刪除的完整操作步驟

Redis Cluster添加、刪除的完整操作步驟

熱門標(biāo)簽:地圖標(biāo)注費(fèi)用 小紅書怎么地圖標(biāo)注店 西藏教育智能外呼系統(tǒng)價(jià)格 玄武湖地圖標(biāo)注 地圖標(biāo)注如何即時(shí)生效 百度商家地圖標(biāo)注怎么做 太原營(yíng)銷外呼系統(tǒng) 竹間科技AI電銷機(jī)器人 最簡(jiǎn)單的百度地圖標(biāo)注

前言

最近學(xué)習(xí)了Redis,發(fā)現(xiàn)Redis還是挺好玩的,今天測(cè)試了集群的添加、刪除節(jié)點(diǎn)、重分配slot等。更深入的理解redis的游戲規(guī)則。步驟繁多,但是詳細(xì),話不多說了,來一起看看詳細(xì)的介紹吧。

環(huán)境解釋:

我是在一臺(tái)Centos 6.9上測(cè)試的,各個(gè)redis節(jié)點(diǎn)以端口號(hào)區(qū)分。文中針對(duì)各個(gè)redis,我只是以端口號(hào)代表。

~~~~Master Node~~~~~
172.16.32.116:7000
172.16.32.116:7001
172.16.32.116:7002
~~~~Slave Node~~~~~
172.16.32.116:8000
172.16.32.116:8001
172.16.32.116:8002
~~~~用來折騰的Node~~~~~
172.16.32.116:9000
172.16.32.116:9001

1. 創(chuàng)建redis集群

注:更多redis集群創(chuàng)建,請(qǐng)參閱

Redis Cluster集群部署搭建            

# ./redis-trib.rb create --replicas 1 172.16.32.116:7000 172.16.32.116:7001 172.16.32.116:7002 172.16.32.116:8000 172.16.32.116:8001 172.16.32.116:8002
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
172.16.32.116:7000
172.16.32.116:7001
172.16.32.116:7002
Adding replica 172.16.32.116:8000 to 172.16.32.116:7000
Adding replica 172.16.32.116:8001 to 172.16.32.116:7001
Adding replica 172.16.32.116:8002 to 172.16.32.116:7002
M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000
 slots:0-5460 (5461 slots) master
M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5461-10922 (5462 slots) master
M: 88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002
 slots:10923-16383 (5461 slots) master
S: aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000
 replicates a0b91f48e933c1f1d427c54917ce970bd25d29f8
S: a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001
 replicates 273107e5ac994d675749be0979556e761274bb93
S: 3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002
 replicates 88fe075375295b59eabe69fa1438ed7c7c314f43
Can I set the above configuration? (type 'yes' to accept): yes
>>> 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 172.16.32.116:7000)
M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000
 slots:0-5460 (5461 slots) master
M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5461-10922 (5462 slots) master
M: 88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002
 slots:10923-16383 (5461 slots) master
M: aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000
 slots: (0 slots) master
 replicates a0b91f48e933c1f1d427c54917ce970bd25d29f8
M: a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001
 slots: (0 slots) master
 replicates 273107e5ac994d675749be0979556e761274bb93
M: 3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002
 slots: (0 slots) master
 replicates 88fe075375295b59eabe69fa1438ed7c7c314f43
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

2. 檢查集群狀態(tài)

# ./redis-trib.rb check 172.16.32.116:7000
>>> Performing Cluster Check (using node 172.16.32.116:7000)
M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000
 slots:0-5460 (5461 slots) master
 1 additional replica(s)
M: 88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002
 slots:10923-16383 (5461 slots) master
 1 additional replica(s)
M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5461-10922 (5462 slots) master
 1 additional replica(s)
S: 3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002
 slots: (0 slots) slave
 replicates 88fe075375295b59eabe69fa1438ed7c7c314f43
S: a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001
 slots: (0 slots) slave
 replicates 273107e5ac994d675749be0979556e761274bb93
S: aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000
 slots: (0 slots) slave
 replicates a0b91f48e933c1f1d427c54917ce970bd25d29f8
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

~~~~~~~~~~~~~~~~~~~~~~~~~~~添加節(jié)點(diǎn)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3. 添加新節(jié)點(diǎn)redis-trib.rb add-node 新增節(jié)點(diǎn)名  原集群節(jié)點(diǎn)名

# ./redis-trib.rb add-node 172.16.32.116:9000 172.16.32.116:7000
>>> Adding node 172.16.32.116:9000 to cluster 172.16.32.116:7000
>>> Performing Cluster Check (using node 172.16.32.116:7000)
M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000
 slots:0-5460 (5461 slots) master
 1 additional replica(s)
M: 88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002
 slots:10923-16383 (5461 slots) master
 1 additional replica(s)
M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5461-10922 (5462 slots) master
 1 additional replica(s)
S: 3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002
 slots: (0 slots) slave
 replicates 88fe075375295b59eabe69fa1438ed7c7c314f43
S: a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001
 slots: (0 slots) slave
 replicates 273107e5ac994d675749be0979556e761274bb93
S: aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000
 slots: (0 slots) slave
 replicates a0b91f48e933c1f1d427c54917ce970bd25d29f8
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...

4. 查看當(dāng)前集群狀態(tài),9000是一個(gè)空的Master

# ./redis-cli -p 9000 cluster nodes
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505321254767 1 connected 0-5460
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505321250759 2 connected 5461-10922
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505321251761 3 connected 10923-16383
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505321255769 3 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505321253765 1 connected
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505321256771 2 connected

5. 為9000分配slot, redis的solt是固定的,就16384個(gè),只能從其他節(jié)點(diǎn)獲取slot,然后分配到9000

# ./redis-trib.rb reshard 172.16.32.116:9000
>>> Performing Cluster Check (using node 172.16.32.116:9000)
M: 364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000
 slots: (0 slots) master
 0 additional replica(s)
M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000
 slots:0-5460 (5461 slots) master
 1 additional replica(s)
M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5461-10922 (5462 slots) master
 1 additional replica(s)
S: 3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002
 slots: (0 slots) slave
 replicates 88fe075375295b59eabe69fa1438ed7c7c314f43
S: aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000
 slots: (0 slots) slave
 replicates a0b91f48e933c1f1d427c54917ce970bd25d29f8
M: 88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002
 slots:10923-16383 (5461 slots) master
 1 additional replica(s)
S: a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001
 slots: (0 slots) slave
 replicates 273107e5ac994d675749be0979556e761274bb93
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 
What is the receiving node ID? 364ae8322ab2627e25b05d45b702448c74afad10 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:all 
Ready to move 300 slots.
 Source nodes:
 M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000
 slots:0-5460 (5461 slots) master
 1 additional replica(s)
 M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5461-10922 (5462 slots) master
 1 additional replica(s)
 M: 88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002
 slots:10923-16383 (5461 slots) master
 1 additional replica(s)
 Destination node:
 M: 364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000
 slots: (0 slots) master
 0 additional replica(s)
 Resharding plan:
 Moving slot 5461 from 273107e5ac994d675749be0979556e761274bb93
 Moving slot 5469 from 273107e5ac994d675749be0979556e761274bb93
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 5461 from 172.16.32.116:7001 to 172.16.32.116:9000:

6. 可以看到,9000已經(jīng)分配到的slot是0-98 5461-5561 10923-11021

# ./redis-cli -p 9000 cluster nodes
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505324905062 1 connected 99-5460
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505324910075 2 connected 5562-10922
364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000 myself,master - 0 0 7 connected 0-98 5461-5561 10923-11021
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505324908070 3 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505324911077 1 connected
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505324902057 3 connected 11022-16383
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505324909073 2 connected

~~~~~~~~~~~~~~~~~~~~~~~~~~~將9000變?yōu)閟lave~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

7. 希望將9000變成7000的slave,但是由于有slot,執(zhí)行失敗,需要先轉(zhuǎn)移slot

# redis-cli -c -p 9000 cluster replicate a0b91f48e933c1f1d427c54917ce970bd25d29f8
(error) ERR To set a master the node must be empty and without assigned slots.

8. 刪除節(jié)點(diǎn)也是不可以的,總之,只要上面有slot。redis是不會(huì)讓你刪除的,而且需要人工介入,rebalance這些slot之后才行

# ./redis-trib.rb del-node 172.16.32.116:9000 364ae8322ab2627e25b05d45b702448c74afad10
>>> Removing node 364ae8322ab2627e25b05d45b702448c74afad10 from cluster 172.16.32.116:9000
[ERR] Node 172.16.32.116:9000 is not empty! Reshard data away and try again.

9.重新分配9000的slot到7000上

# ./redis-trib.rb reshard 172.16.32.116:9000 重新分配slot
>>> Performing Cluster Check (using node 172.16.32.116:9000)
M: 364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000
 slots:0-98,5461-5561,10923-11021 (299 slots) master
 0 additional replica(s)
M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000
 slots:99-5460 (5362 slots) master
 1 additional replica(s)
M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5562-10922 (5361 slots) master
 1 additional replica(s)
S: 3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002
 slots: (0 slots) slave
 replicates 88fe075375295b59eabe69fa1438ed7c7c314f43
S: aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000
 slots: (0 slots) slave
 replicates a0b91f48e933c1f1d427c54917ce970bd25d29f8
M: 88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002
 slots:11022-16383 (5362 slots) master
 1 additional replica(s)
S: a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001
 slots: (0 slots) slave
 replicates 273107e5ac994d675749be0979556e761274bb93
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 300  9000節(jié)點(diǎn)全部需要遷移的節(jié)點(diǎn)
What is the receiving node ID? a0b91f48e933c1f1d427c54917ce970bd25d29f8 7000的ID
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:364ae8322ab2627e25b05d45b702448c74afad10 9000的ID
Source node #2:done
Ready to move 300 slots.
 Source nodes:
 M: 364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000 Source nodes
 slots:0-98,5461-5561,10923-11021 (299 slots) master
 0 additional replica(s)
 Destination node:
 M: a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 Destination node
 slots:99-5460 (5362 slots) master
 1 additional replica(s)
 Resharding plan:
 Moving slot 0 from 364ae8322ab2627e25b05d45b702448c74afad10
.........
 Moving slot 11021 from 364ae8322ab2627e25b05d45b702448c74afad10
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 0 from 172.16.32.116:9000 to 172.16.32.116:7000:
Moving slot 1 from 172.16.32.116:9000 to 172.16.32.116:7000:
........

10. 查詢,可以看到9000已經(jīng)沒有slot了

# ./redis-cli -p 9000 cluster nodes
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505328938056 8 connected 0-5561 10923-11021
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505328939059 2 connected 5562-10922
364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000 myself,master - 0 0 7 connected
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505328936053 3 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505328933046 8 connected
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505328937054 3 connected 11022-16383
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505328934049 2 connected

11. 再次執(zhí)行命令,將9000變成7000的slave,成功

# redis-cli -c -p 9000 cluster replicate a0b91f48e933c1f1d427c54917ce970bd25d29f8
OK

12. 查看狀態(tài),9000已經(jīng)成為7000的slave

# ./redis-cli -p 9000 cluster nodes
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505329564286 8 connected 0-5561 10923-11021
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505329561281 2 connected 5562-10922
364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000 myself,slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 0 7 connected 
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505329558274 3 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505329554266 8 connected
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505329563285 3 connected 11022-16383
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505329562283 2 connected

13. 刪除節(jié)點(diǎn)9000,成功刪除

# ./redis-trib.rb del-node 172.16.32.116:9000 364ae8322ab2627e25b05d45b702448c74afad10
>>> Removing node 364ae8322ab2627e25b05d45b702448c74afad10 from cluster 172.16.32.116:9000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

14. 連接9000,發(fā)現(xiàn)已經(jīng)shutdown,無法連接

# ./redis-cli -p 9000 cluster nodes
Could not connect to Redis at 127.0.0.1:9000: Connection refused
Could not connect to Redis at 127.0.0.1:9000: Connection refused

15. 查看集群狀態(tài),9000已經(jīng)不見了

# ./redis-cli -p 7000 cluster nodes
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505329693835 3 connected 11022-16383
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505329694837 2 connected 5562-10922
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 myself,master - 0 0 8 connected 0-5561 10923-11021
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505329696841 6 connected
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505329695840 5 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505329692833 8 connected

~~~~~~~~~~~~~~~~~~~~~~~~~~~再次啟動(dòng)9000,發(fā)現(xiàn)不同~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

16. 再次啟動(dòng)9000,發(fā)現(xiàn)一個(gè)有意思的事情。上面檢查7000,集群已經(jīng)沒有9000了

# ./redis-cli -p 7000 cluster nodes
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505329898241 3 connected 11022-16383
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505329899242 2 connected 5562-10922
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 myself,master - 0 0 8 connected 0-5561 10923-11021
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505329902249 6 connected
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505329901246 5 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505329900244 8 connected

17. 但是查看9000,確仍然能看到整個(gè)集群的信息。

說明,在刪除節(jié)點(diǎn)的過程,只是在原有集群中刪除9000的信息。但是9000自身的信息并沒有被刪除,依然保留全部的信息,只是9000實(shí)例被關(guān)閉而已。

# ./redis-cli -p 9000 cluster nodes
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505329902003 8 connected 0-5561 10923-11021
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505329903006 2 connected 5562-10922
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505329906013 3 connected
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505329908019 2 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505329904008 8 connected
364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000 myself,slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 0 7 connected
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505329907016 3 connected 11022-16383

18. 而9000的全部信息,是記錄在自身目錄的nodes.conf中

# more nodes.conf
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505329544244 8 connected 0-5561 10923-11021
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 master - 0 1505329542241 2 connected 5562-10922
364ae8322ab2627e25b05d45b702448c74afad10 172.16.32.116:9000 myself,slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 0 7 connected
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505329541239 3 connected
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505329545246 8 connected
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505329543242 3 connected 11022-16383
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505329546248 2 connected
vars currentEpoch 8 lastVoteEpoch 0

19. 到7001等其他節(jié)點(diǎn)中查看,nodes.conf已經(jīng)沒有9000的信息

# more nodes.conf
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 myself,master - 0 0 2 connected 5562-10922
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505329680312 8 connected 0-5561 10923-11021
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505329684319 8 connected
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505329686321 6 connected
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505329685318 5 connected
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505329683317 3 connected 11022-16383
vars currentEpoch 8 lastVoteEpoch 0

~~~~~~~~~~~~~~~~~~~~~~~~~~~再次添加9000,以及9001~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

20. 將9000和9001再次加入集群,開始下面的折騰。

注意:需要將9000和9001下的redis.conf外的文件清除,重啟。然后才能再次加入集群。不然會(huì)遇到錯(cuò)誤:

[ERR] Node 172.16.32.116:9001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

21. 加入集群

./redis-trib.rb add-node 172.16.32.116:9000 172.16.32.116:7002
./redis-trib.rb add-node 172.16.32.116:9001 172.16.32.116:7002

22. 現(xiàn)在是兩個(gè)空的Master節(jié)點(diǎn)

# ./redis-trib.rb check 172.16.32.116:9001
>>> Performing Cluster Check (using node 172.16.32.116:9001)
M: c4ba7a1f537ac66076791461d6af9012741fee74 172.16.32.116:9001
 slots: (0 slots) master
 0 additional replica(s)
M: dbf78b73f2ab9e37cbf31abbc2beb3d5413d5516 172.16.32.116:9000
 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.

23. 重分配100個(gè)slot到9000上,其實(shí)redis很聰明的,我連接的是9001,但是在分配的時(shí)候,它會(huì)問你,receiving node是誰,Source node 是誰。

# ./redis-trib.rb reshard 172.16.32.116:9001
>>> Performing Cluster Check (using node 172.16.32.116:9001)
......
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 100
What is the receiving node ID? dbf78b73f2ab9e37cbf31abbc2beb3d5413d5516 receiving node ID
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:aeb684429d220c0fd1392574d193cc1ae7577782 Source node我選的是 8000
*** The specified node is not known or is not a master, please retry. 然而,并沒能欺騙redis,它發(fā)現(xiàn)了,這個(gè)是slave,沒有slot可以提供的。 
Source node #1:273107e5ac994d675749be0979556e761274bb93 Source node再次指定為7001,開始分配了
Source node #2:done
Ready to move 100 slots.
 Source nodes:
 M: 273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001
 slots:5562-10922 (5361 slots) master
 1 additional replica(s)
 Destination node:
 M: dbf78b73f2ab9e37cbf31abbc2beb3d5413d5516 172.16.32.116:9000
 slots: (0 slots) master
 0 additional replica(s)
 Resharding plan:
 Moving slot 5562 from 273107e5ac994d675749be0979556e761274bb93
 Moving slot 5563 from 273107e5ac994d675749be0979556e761274bb93

24. 查看分配情況,redis還是很聰明靈活的。

# redis-cli -p 7001 cluster nodes
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 myself,master - 0 0 2 connected 5662-10922
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505330856605 8 connected 0-5561 10923-11021
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505330853598 8 connected
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505330860611 6 connected
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505330859608 5 connected
c4ba7a1f537ac66076791461d6af9012741fee74 172.16.32.116:9001 master - 0 1505330862615 9 connected       依然是空的
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505330861612 3 connected 11022-16383
dbf78b73f2ab9e37cbf31abbc2beb3d5413d5516 172.16.32.116:9000 master - 0 1505330858607 10 connected 5562-5661    從7001要來100個(gè)slot

25. 將9001添加為9000的slave節(jié)點(diǎn) redis-cli -p slave IP:port> cluster nodes Master ID 號(hào)>

# redis-cli -p 9001 cluster nodes dbf78b73f2ab9e37cbf31abbc2beb3d5413d5516
273107e5ac994d675749be0979556e761274bb93 172.16.32.116:7001 myself,master - 0 0 2 connected 5662-10922
a0b91f48e933c1f1d427c54917ce970bd25d29f8 172.16.32.116:7000 master - 0 1505331457798 8 connected 0-5561 10923-11021
aeb684429d220c0fd1392574d193cc1ae7577782 172.16.32.116:8000 slave a0b91f48e933c1f1d427c54917ce970bd25d29f8 0 1505331454791 8 connected
3d27f60a1cc4d9c8f09aca928b03f0e083722d3b 172.16.32.116:8002 slave 88fe075375295b59eabe69fa1438ed7c7c314f43 0 1505331456795 6 connected
a96cad95dca2a8e1e0302bff4f835260d92e3d31 172.16.32.116:8001 slave 273107e5ac994d675749be0979556e761274bb93 0 1505331458799 10 connected
c4ba7a1f537ac66076791461d6af9012741fee74 172.16.32.116:9001 slave dbf78b73f2ab9e37cbf31abbc2beb3d5413d5516 0 1505331459801 10 connected
88fe075375295b59eabe69fa1438ed7c7c314f43 172.16.32.116:7002 master - 0 1505331455793 3 connected 11022-16383
dbf78b73f2ab9e37cbf31abbc2beb3d5413d5516 172.16.32.116:9000 master - 0 1505331453788 10 connected 5562-5661

經(jīng)過各種折騰,redis添加,刪除,重分配slot等操作,都測(cè)試完了。

中間有很多命令輸出部門,視乎有點(diǎn)重復(fù)。但是為了更好的閱讀理解,觀察每一步操作的變化。后面查閱也更容易一些。
畢竟,年紀(jì)大了,記性不好。好多自己寫過的blog,回頭翻閱的時(shí)候,發(fā)現(xiàn)某些步驟,不是很好理解了。雖然我的blog,都是基于自己測(cè)試的結(jié)果,但是依然會(huì)忘記。

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

您可能感興趣的文章:
  • 詳解SpringBoot Redis自適應(yīng)配置(Cluster Standalone Sentinel)
  • Redis Cluster集群數(shù)據(jù)分片機(jī)制原理
  • docker redis5.0 cluster集群搭建的實(shí)現(xiàn)
  • 使用Ruby腳本部署Redis Cluster集群步驟講解
  • php成功操作redis cluster集群的實(shí)例教程
  • Redis cluster集群的介紹
  • Windows環(huán)境下Redis Cluster環(huán)境搭建(圖文)
  • 如何用docker部署redis cluster的方法
  • spring集成redis cluster詳解
  • 解析Redis Cluster原理

標(biāo)簽:唐山 揚(yáng)州 澳門 景德鎮(zhèn) 香港 林芝 廣東 贛州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Redis Cluster添加、刪除的完整操作步驟》,本文關(guān)鍵詞  Redis,Cluster,添加,刪除,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Redis Cluster添加、刪除的完整操作步驟》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Redis Cluster添加、刪除的完整操作步驟的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章