redis cluster 添加删除节点

目前集群环境
主节点:172.21.20.10:6379\6380\6381
从节点:172.21.20.10:6372\6383\6384

添加主从节点:172.21.20.10:6385\6386

一、添加节点
1、新配置两个节点

# cp redis-6379.conf redis-6385.conf && sed -i "s/6379/6385/g" redis-6385.conf  
# cp redis-6379.conf redis-6386.conf && sed -i "s/6382/6386/g" redis-6386.conf

#./src/redis-server conf/redis-6385.conf 
#./src/redis-server conf/redis-6386.conf 

2、添加主节点

#./src/redis-trib.rb add-node 172.21.20.10:6385 172.21.20.10:7379

注释:

172.21.20.10:6385 是新增的节点

172.21.20.10:7379集群任一个旧节点

node:新节点没有包含任何数据, 因为它没有包含任何slot。新加入的加点是一个主节点, 当集群需要将某个从节点升级为新的主节点时, 这个新节点不会被选中,同时新的主节点因为没有包含任何slot,不参加选举和failover
3、添加从节点

#./src/redis-trib.rb add-node 172.21.20.10:6386 172.21.20.10:7379
#./src/redis-cli -c -p 6386 -a '123456'
# cluster replicate 2764e7bb5a280a5e14d085fb4d002e89cae53f08
或者
#/src/redis-trib.rb add-node --slave --master-id 2764e7bb5a280a5e14d085fb4d002e89cae53f08  172.21.20.10:6385 172.21.20.10:6379  

注释:
cluster replicate 对应master的node-id
–slave,表示添加的是从节点
–master-id 2764e7bb5a280a5e14d085fb4d002e89cae53f08 ,主节点的node id,在这里是前面新添加的6385的node id
172.21.20.10:6385,新节点
172.21.20.10:6379集群任一个旧节点
4、为新节点分配solt

    # redis-trib.rb reshard 172.21.20.10:6385 //下面是主要过程  
    How many slots do you want to move (from 1 to 16384)? 1000 //设置slot数1000  
    What is the receiving node ID? 2764e7bb5a280a5e14d085fb4d002e89cae53f08//新节点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:all //表示全部节点重新洗牌  
    Do you want to proceed with the proposed reshard plan (yes/no)? yes //确认重新分  

5、检查集群状况

./src/redis-trib.rb check 172.21.20.10:6385

二、删除节点
1、删除从节点

./src/redis-trib.rb del-node 172.21.20.10:6386 '19498b903825a010346d3c1fdab6f0083785705e'

2、删除主节点
如果主节点有从节点,将从节点转移到其他主节点

如果主节点有slot,去掉分配的slot,然后在删除主节点

# redis-trib.rb reshard 172.21.20.10:6379  //取消分配的slot,下面是主要过程  

How many slots do you want to move (from 1 to 16384)? 1000 //被删除master的所有slot数量  
What is the receiving node ID? e958c6730e3093e0f914d3644d499bce40e61dfb//接收6385节点slot的master  
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:2764e7bb5a280a5e14d085fb4d002e89cae53f08//被删除master的node-id  
Source node #2:done   

Do you want to proceed with the proposed reshard plan (yes/no)? yes //取消slot后,reshard


./src/redis-trib.rb del-node 172.21.20.10:6385 '2764e7bb5a280a5e14d085fb4d002e89cae53f08'

猜你喜欢

转载自blog.csdn.net/jing956899449/article/details/56842837