返回顶部
首页 > 资讯 > 数据库 >Redis Cluster添加、删除的完整操作步骤
  • 217
分享到

Redis Cluster添加、删除的完整操作步骤

操作步骤完整Redis 2022-06-04 17:06:50 217人浏览 薄情痞子
摘要

前言 最近学习了Redis,发现Redis还是挺好玩的,今天测试了集群的添加、删除节点、重分配slot等。更深入的理解redis的游戏规则。步骤繁多,但是详细,话不多说了,来一起看看详细的介绍吧。 环境解释

前言

最近学习Redis,发现Redis还是挺好玩的,今天测试集群的添加、删除节点、重分配slot等。更深入的理解redis的游戏规则。步骤繁多,但是详细,话不多说了,来一起看看详细的介绍吧。

环境解释:

我是在一台Centos 6.9上测试的,各个redis节点以端口号区分。文中针对各个redis,我只是以端口号代表。


~~~~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. 创建redis集群

注:更多redis集群创建,请参阅

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. 检查集群状态


# ./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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~添加节点~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

3. 添加新节点redis-trib.rb add-node 新增节点名 原集群节点名


# ./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. 查看当前集群状态,9000是一个空的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个,只能从其他节点获取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已经分配到的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变为slave~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

7. 希望将9000变成7000的slave,但是由于有slot,执行失败,需要先转移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. 删除节点也是不可以的,总之,只要上面有slot。redis是不会让你删除的,而且需要人工介入,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节点全部需要迁移的节点
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已经没有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. 再次执行命令,将9000变成7000的slave,成功


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

12. 查看状态,9000已经成为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. 删除节点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,发现已经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. 查看集群状态,9000已经不见了


# ./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

~~~~~~~~~~~~~~~~~~~~~~~~~~~再次启动9000,发现不同~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

16. 再次启动9000,发现一个有意思的事情。上面检查7000,集群已经没有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,确仍然能看到整个集群的信息。

说明,在删除节点的过程,只是在原有集群中删除9000的信息。但是9000自身的信息并没有被删除,依然保留全部的信息,只是9000实例被关闭而已。


# ./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等其他节点中查看,nodes.conf已经没有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外的文件清除,重启。然后才能再次加入集群。不然会遇到错误:


[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. 现在是两个空的Master节点


# ./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个slot到9000上,其实redis很聪明的,我连接的是9001,但是在分配的时候,它会问你,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,它发现了,这个是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个slot

25. 将9001添加为9000的slave节点 redis-cli -p <slave IP:port> cluster nodes <Master ID 号>


# 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

经过各种折腾,redis添加,删除,重分配slot等操作,都测试完了。

中间有很多命令输出部门,视乎有点重复。但是为了更好的阅读理解,观察每一步操作的变化。后面查阅也更容易一些。
毕竟,年纪大了,记性不好。好多自己写过的blog,回头翻阅的时候,发现某些步骤,不是很好理解了。虽然我的blog,都是基于自己测试的结果,但是依然会忘记。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对编程网的支持。

您可能感兴趣的文档:

--结束END--

本文标题: Redis Cluster添加、删除的完整操作步骤

本文链接: https://lsjlt.com/news/11768.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • Redis Cluster添加、删除的完整操作步骤
    前言 最近学习了Redis,发现Redis还是挺好玩的,今天测试了集群的添加、删除节点、重分配slot等。更深入的理解redis的游戏规则。步骤繁多,但是详细,话不多说了,来一起看看详细的介绍吧。 环境解释...
    99+
    2022-06-04
    操作步骤 完整 Redis
  • 添加服务器操作步骤
    第一步:找到相应的账号,看其分配了哪些服务器,如下图所示是个人账号分配的服务器,包括服务器地址、端口号(Port)、服务器类型以及加密方式 第二步:打开V2rayN软件,添加相应的服务器,如下...
    99+
    2023-09-08
    服务器 运维 Powered by 金山文档
  • navicat中添加约束的操作步骤
    小编给大家分享一下navicat中添加约束的操作步骤,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!打开navicat工具连接上mysql服务,然后选择打开一个数据库,这里为了演示选择一个测...
    99+
    2024-04-02
  • Discuz删除回复的操作步骤详解
    Discuz删除回复的操作步骤详解 在Discuz论坛管理中,删除回复是常见的操作之一,可以对不符合规定或者有害信息的回复进行清理。下面将详细介绍在Discuz中删除回复的具体操作步骤...
    99+
    2024-03-10
    进入“管理中心” 选择“删除”操作
  • windows8系统主题删除操作步骤
    不折腾不顺坦,相信大家入手Win8之后第一件事就是安装各种各样的Win8主题吧!那么,安装的这些Win8主题如何删除呢右键点击也看不到删除选项啊! 操作步骤 1、其实想要删除Windows8主题,首先我们要...
    99+
    2022-06-04
    操作步骤 主题 系统
  • js实现添加删除表格操作
    本文实例为大家分享了js实现添加删除表格的具体代码,供大家参考,具体内容如下 效果: 1、点击添加按钮 往table中添加一行  将全选前面的复选框变成false 1.1....
    99+
    2024-04-02
  • SpringBoot 添加本地 jar 文件的操作步骤
    前言 有时候我们在项目中,会用到一些本地 jar 包文件,比如隔壁公司自己打包的; 此时无法从maven远程仓库拉取; 那么我们可以考虑把 jar 文件安装到本地 maven 库中,...
    99+
    2024-04-02
  • ubuntu下Matlab_Linux添加工具包操作步骤
    以下以rvctools为例 具体操作如下: 1. 先将下载好的压缩包(robot-9.10.zip)解压,得到工具包rvctools 2. 将该工具包复制到MATLAB下的toolbox文件夹内,一般是无法将工具包复制进...
    99+
    2022-06-04
    ubuntu 工具包 matlab linux
  • windows7添加开机启动项操作步骤
    有些用户想要将自己常见的一些软件使用成开机启动,这样就可便捷打开和使用了,那么windows7如何添加开机启动项呢?其实操作步骤特别简单,你先点击桌面左下方的开始菜单,随后挑选所有程序,以后找到启动右键打开,将桌面要想设定开机启动的运用拖至...
    99+
    2023-07-15
  • 安装redis的操作步骤
    小编给大家分享一下安装redis的操作步骤,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!1、下载安装包下载地址:https://github.com/MSOpenTech/redis/rele...
    99+
    2024-04-02
  • Redis读写分离搭建的完整步骤
    目录1、概述2、读写分离的搭建2.1 场景说明2.2 修改从服务器A和从服务B的Redis配置2.3 删除从服务器A和从服务器B的数据文件2.4 重启从服务器A和从服务器B2.5 查...
    99+
    2024-04-02
  • C# WPF数据绑定模板化操作的完整步骤
    目录前言:具体实例代码如下:总结前言: WPF数据绑定对于WPF应用程序来说尤为重要,本文将讲述使用MVVM模式进行数据绑定的四步走用法: 具体实例代码如下: public cla...
    99+
    2024-04-02
  • 利用Python制作PPT的完整步骤
    目录前言步骤1:步骤2:安装PIP3步骤3:安装python-pptx4.写代码测试:总结前言 怎么,你还没学Python吗? 此一时彼以时,什么C,JAVA,现在在求职市场...
    99+
    2024-04-02
  • redis删除指定key的实现步骤
    1.打开Redis目录并打开redis-cli.exe 如果直接输入get key会出现以下问题,表示需要认证,也就是需要登录用户 使用auth password登录即可 然后使用get key获取键的值 确认后...
    99+
    2022-08-17
    redis删除指定key redis删除key
  • Win7系统向U盘添加密码的操作步骤
    大量用户选择使用Win7作为最稳定的Windows操作系统。使用Win7系统有很多技巧。最近很多朋友都很好奇如何用Win7系统给U盘加密码,所以今天就和大家分享一下Win7系统给U盘加密码的方法。让我们一起学习。点击【菜单】,找到【Lock...
    99+
    2023-07-12
  • Redis集群水平扩展、集群中添加以及删除节点的操作
    在Redis集群搭建中,我们搭建了下图所示的Redis集群,接下来我们就来看看如何为我们的Redis集群进行水平扩容。 [root@localhost redis-5.0.3]...
    99+
    2024-04-02
  • Ubuntu 添加删除开机启动项的操作方法
    Ubuntu或者Debian系统中update-rc.d命令,是用来更新系统启动项的脚本。这些脚本的链接位于/etc/rcN.d/目录,对应脚本位于/etc/init.d/目录。在了解update-rc.d命令之前,你需...
    99+
    2022-06-04
    ubuntu添加开机启动项
  • Linux操作系统彻底删除MySQL——详细步骤
    Linux彻底删除MySQL 注意:在安装另一个MySQL版本之前一定要把之前MySQL版本给卸载干净。 详细步骤如下: 1、检查云服务器是否已经安装了MySQL: rpm -qa | grep mysql 如下所示: m...
    99+
    2023-08-19
    mysql linux 服务器 后端 运维
  • js动态实现表格添加和删除操作
    本文实例为大家分享了js动态实现表格添加和删除的具体代码,供大家参考,具体内容如下 运行效果如图(两种实现方案,被注释的是第一种实现方案) 代码: <!DOCTYPE h...
    99+
    2024-04-02
  • Oracle 11g实现安全加固的完整步骤
    前言 数据库安全配置中,需要做相关的安全加固工作。以确认数据库的安全,但是,有些时候,操作不当或者数据库业务账号修改密码后,而程序的连接数据库的配置封装在jar里,如果jar内的连接数据库的配置信息没有做相...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作