DevOps/SRE

Docker 搭建Redis集群环境

2022-04-07  本文已影响0人  雨醉风尘

[toc]

一:启动6个Redis容器实例

docker run -d --name redis-node-1 --net host --privileged=true -v D:\Docker\redis-share\redis-node-1:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6381

docker run -d --name redis-node-2 --net host --privileged=true -v D:\Docker\redis-share\redis-node-2:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6382

docker run -d --name redis-node-3 --net host --privileged=true -v D:\Docker\redis-share\redis-node-3:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6383

docker run -d --name redis-node-4 --net host --privileged=true -v D:\Docker\redis-share\redis-node-4:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6384

docker run -d --name redis-node-5 --net host --privileged=true -v D:\Docker\redis-share\redis-node-5:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6385

docker run -d --name redis-node-6 --net host --privileged=true -v D:\Docker\redis-share\redis-node-6:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6386


二:进入容器 redis-node-1 并为6台机器构建集群关系

docker exec -it redis-node-1 /bin/bash

redis-cli --cluster create 192.168.43.176:6381 192.168.43.176:6382 192.168.43.176:6383 192.168.43.176:6384 192.168.43.176:6385 192.168.43.176:6386 --cluster-replicas 1

redis-cli --cluster create 192.168.43.176:6381 192.168.43.176:6382 192.168.43.176:6383 192.168.43.176:6384 192.168.43.176:6385 192.168.43.176:6386 --cluster-replicas 1

--cluster-replicas 1 表示为每一个master创建一个slave节点

root@docker-desktop:/data# redis-cli --cluster create 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 127.0.0.1:6385 127.0.0.1:6386 --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:6385 to 127.0.0.1:6381
Adding replica 127.0.0.1:6386 to 127.0.0.1:6382
Adding replica 127.0.0.1:6384 to 127.0.0.1:6383
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[0-5460] (5461 slots) master
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[5461-10922] (5462 slots) master
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[10923-16383] (5461 slots) master
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   replicates a13417523319078aeb96fe85814d745349798914
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
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 127.0.0.1:6381)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

三:链接进入6381作为切入点,查看集群状态
root@docker-desktop:/data# redis-cli -p 6381
127.0.0.1:6381> keys *
(empty array)
127.0.0.1:6381> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:228
cluster_stats_messages_pong_sent:249
cluster_stats_messages_sent:477
cluster_stats_messages_ping_received:244
cluster_stats_messages_pong_received:228
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:477
127.0.0.1:6381> cluster nodes
af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384@16384 slave 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 0 1649171931198 1 connected
3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381@16381 myself,master - 0 1649171934000 1 connected 0-5460
b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383@16383 master - 0 1649171934212 3 connected 10923-16383
a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382@16382 master - 0 1649171935214 2 connected 5461-10922
93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386@16386 slave b42b70e3d1208919ece928bd49e1c67a41121a0f 0 1649171933208 3 connected
fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385@16385 slave a13417523319078aeb96fe85814d745349798914 0 1649171933000 2 connected

四:通过集群连接模式进入redis

redis-cli -p 6381 -c


五:查看集群信息

redis-cli --cluster check host:port

redis-cli --cluster check 127.0.0.1:6381


六:主从容错切换

docker stop redis-node-1

1:启动6381 节点,此时6381作为6385的从节点

2:停掉6385 节点,此时从节点6381 升级为主节点

3:启动6385,此时6385作为6381的从节点


七:集群扩容

docker run -d --name redis-node-7 --net host --privileged=true -v D:\Docker\redis-share\redis-node-7:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6387

docker run -d --name redis-node-8 --net host --privileged=true -v D:\Docker\redis-share\redis-node-8:/data redis:6.0.8 --cluster-enabled yes --appendonly yes --port 6388

docker exec -it redis-node-7 /bin/bash

【ip_x:port_x】 加入到集群 【ip_a:port_a】

redis-cli --cluster add-node ip_x:port_x ip_a:port_a(作为基准的ip+port)

redis-cli --cluster add-node 127.0.0.1:6387 127.0.0.1:6381

root@docker-desktop:/data# redis-cli --cluster add-node 127.0.0.1:6387 127.0.0.1:6381
>>> Adding node 127.0.0.1:6387 to cluster 127.0.0.1:6381
>>> Performing Cluster Check (using node 127.0.0.1:6381)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
[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:6387 to make it join the cluster.
[OK] New node added correctly.

redis-cli --cluster check 127.0.0.1:6387

root@docker-desktop:/data# redis-cli --cluster check 127.0.0.1:6387
# 没有分配槽位
127.0.0.1:6387 (480eb0d7...) -> 0 keys | 0 slots | 0 slaves. 
127.0.0.1:6383 (b42b70e3...) -> 2 keys | 5461 slots | 1 slaves.
127.0.0.1:6381 (3d83a29a...) -> 2 keys | 5461 slots | 1 slaves.
127.0.0.1:6382 (a1341752...) -> 1 keys | 5462 slots | 1 slaves.
[OK] 5 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6387)
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots: (0 slots) master
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

redis-cli --cluster reshard ip:port (之前的一台master实例)

redis-cli --cluster reshard 127.0.0.1:6381

root@docker-desktop:/data# redis-cli --cluster reshard 127.0.0.1:6381
>>> Performing Cluster Check (using node 127.0.0.1:6381)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots: (0 slots) master
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
[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)? 4096 
# 6387节点的id
What is the receiving node ID? 480eb0d7347aad32a55b10ec52375d9651e69030
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 4096 slots.
  Source nodes:
    M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
  Destination node:
    M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
       slots: (0 slots) master
  Resharding plan:
    Moving slot 5461 from a13417523319078aeb96fe85814d745349798914

redis-cli --cluster check 127.0.0.1:6387

root@docker-desktop:/data# redis-cli --cluster check 127.0.0.1:6387
127.0.0.1:6387 (480eb0d7...) -> 1 keys | 4096 slots | 0 slaves.
127.0.0.1:6383 (b42b70e3...) -> 2 keys | 4096 slots | 1 slaves.
127.0.0.1:6381 (3d83a29a...) -> 1 keys | 4096 slots | 1 slaves.
127.0.0.1:6382 (a1341752...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 5 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6387)
# 前三个master节点各自分配一部分槽号给6387
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

redis-cli --cluster add-node 127.0.0.1:6388 127.0.0.1:6387 --cluster-slave --cluster-master-id 480eb0d7347aad32a55b10ec52375d9651e69030

root@docker-desktop:/data# redis-cli --cluster add-node 127.0.0.1:6388 127.0.0.1:6387 --cluster-slave --cluster-master-id 480eb0d7347aad32a55b10ec52375d9651e69030
>>> Adding node 127.0.0.1:6388 to cluster 127.0.0.1:6387
>>> Performing Cluster Check (using node 127.0.0.1:6387)
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
[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:6388 to make it join the cluster.
Waiting for the cluster to join

>>> Configure node as replica of 127.0.0.1:6387.
[OK] New node added correctly.
root@docker-desktop:/data# redis-cli --cluster check 127.0.0.1:6388
127.0.0.1:6381 (3d83a29a...) -> 1 keys | 4096 slots | 1 slaves.
127.0.0.1:6387 (480eb0d7...) -> 1 keys | 4096 slots | 1 slaves.
127.0.0.1:6383 (b42b70e3...) -> 2 keys | 4096 slots | 1 slaves.
127.0.0.1:6382 (a1341752...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 5 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6388)
S: eab39975bc2e9efd23cbfd3dd619efeab752c57d 127.0.0.1:6388
   slots: (0 slots) slave
   replicates 480eb0d7347aad32a55b10ec52375d9651e69030
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

八:集群缩容
root@docker-desktop:/data# redis-cli --cluster check 127.0.0.1:6388
127.0.0.1:6381 (3d83a29a...) -> 1 keys | 4096 slots | 1 slaves.
127.0.0.1:6387 (480eb0d7...) -> 1 keys | 4096 slots | 1 slaves.
127.0.0.1:6383 (b42b70e3...) -> 2 keys | 4096 slots | 1 slaves.
127.0.0.1:6382 (a1341752...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 5 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6388)
# 【6388的id节点号】
S: eab39975bc2e9efd23cbfd3dd619efeab752c57d 127.0.0.1:6388
   slots: (0 slots) slave
   replicates 480eb0d7347aad32a55b10ec52375d9651e69030
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
   1 additional replica(s)
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

redis-cli --cluster del-node ip:port nodeID

redis-cli --cluster del-node 127.0.0.1:6388 eab39975bc2e9efd23cbfd3dd619efeab752c57d

root@docker-desktop:/data# redis-cli --cluster del-node 127.0.0.1:6388 eab39975bc2e9efd23cbfd3dd619efeab752c57d
>>> Removing node eab39975bc2e9efd23cbfd3dd619efeab752c57d from cluster 127.0.0.1:6388
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.

redis-cli --cluster reshard 127.0.0.1:6381

root@docker-desktop:/data# redis-cli --cluster reshard 127.0.0.1:6381
>>> Performing Cluster Check (using node 127.0.0.1:6381)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[1365-5460] (4096 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
[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)? 4096
# 【需要接受槽号的节点id - 6381的节点id】
What is the receiving node ID? 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
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.
 # 【回收槽号的节点id - 6487的节点id】 
Source node #1: 480eb0d7347aad32a55b10ec52375d9651e69030
# 【done】
Source node #2: done

Ready to move 4096 slots.
  Source nodes:
    M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
       slots:[0-1364],[5461-6826],[10923-12287] (4096 slots) master
  Destination node:
    M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
       slots:[1365-5460] (4096 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 0 from 480eb0d7347aad32a55b10ec52375d9651e69030
root@docker-desktop:/data# redis-cli --cluster check 127.0.0.1:6387
127.0.0.1:6387 (480eb0d7...) -> 0 keys | 0 slots | 0 slaves.
127.0.0.1:6383 (b42b70e3...) -> 2 keys | 4096 slots | 1 slaves.
127.0.0.1:6381 (3d83a29a...) -> 2 keys | 8192 slots | 1 slaves.
127.0.0.1:6382 (a1341752...) -> 1 keys | 4096 slots | 1 slaves.
[OK] 5 keys in 4 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6387)
#注意【此时6387节点已经没有槽位了】
M: 480eb0d7347aad32a55b10ec52375d9651e69030 127.0.0.1:6387
   slots: (0 slots) master
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
   
 # 【6381节点有两个槽位段了】 
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[0-6826],[10923-12287] (8192 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

redis-cli --cluster del-node 127.0.0.1:6387 480eb0d7347aad32a55b10ec52375d9651e69030

root@docker-desktop:/data# redis-cli --cluster del-node 127.0.0.1:6387 480eb0d7347aad32a55b10ec52375d9651e69030
>>> Removing node 480eb0d7347aad32a55b10ec52375d9651e69030 from cluster 127.0.0.1:6387
>>> Sending CLUSTER FORGET messages to the cluster...
>>> Sending CLUSTER RESET SOFT to the deleted node.
root@docker-desktop:/data# redis-cli --cluster check 127.0.0.1:6381
127.0.0.1:6381 (3d83a29a...) -> 2 keys | 8192 slots | 1 slaves.
127.0.0.1:6382 (a1341752...) -> 1 keys | 4096 slots | 1 slaves.
127.0.0.1:6383 (b42b70e3...) -> 2 keys | 4096 slots | 1 slaves.
[OK] 5 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 127.0.0.1:6381)
M: 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7 127.0.0.1:6381
   slots:[0-6826],[10923-12287] (8192 slots) master
   1 additional replica(s)
M: a13417523319078aeb96fe85814d745349798914 127.0.0.1:6382
   slots:[6827-10922] (4096 slots) master
   1 additional replica(s)
S: fc40e09aaa16cc553803594185a0c7d9e9d0598b 127.0.0.1:6385
   slots: (0 slots) slave
   replicates a13417523319078aeb96fe85814d745349798914
M: b42b70e3d1208919ece928bd49e1c67a41121a0f 127.0.0.1:6383
   slots:[12288-16383] (4096 slots) master
   1 additional replica(s)
S: 93e86133e673e5ae9cea8d0c529a546f710f006d 127.0.0.1:6386
   slots: (0 slots) slave
   replicates b42b70e3d1208919ece928bd49e1c67a41121a0f
S: af55c54373c36edb4f7e60707baf6d3a7ce65c03 127.0.0.1:6384
   slots: (0 slots) slave
   replicates 3d83a29a60619a71b9f1b2db2b1a17d2cadcc2c7
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
上一篇下一篇

猜你喜欢

热点阅读