Redis集群水平扩展添加节点删除节点

在原集群中增加节点,再增加一主一从,在redis 的redis-cluster下 创建8007 8008 目录

cd /opt/redis-5.0.7/redis-cluster
mkdir 8007 8008

复制 8001 的redis 配置文件致 8007与8008

cd 8001
cp redis.conf ../8007/
cp redis.conf ../8008/

修改 8007 和8008 redis.conf 配置文件,通过批量修改命令完成

vim redis.conf	

#命令模式批量替换

:%s/8001/8007
===============
:%s/8001/8008

启动8007 8008 redis服务

cd ../../bin

./redis-server ../redis-cluster/8007/redis.conf

./redis-server ../redis-cluster/8008/redis.conf

添加新节点 使用 --cluster add node 命令

./redis-cli -a admin21262 --cluster add node 192.168.217.128:8007 192.168.217.128:8001

查看集群状态

./redis-cli -a admin21262 -c -h 192.168..217.128 -p 8001

为8007 添加加槽位(新加的节点没有hash 槽 不能使用)

./redis-cli -a admin21262 --cluster reshard 192.168.217.128:8001

输入新增节点占用的槽位(根据自己集群节点合理设置 redis 集群总槽数量是16384)

How many slots do you want to move (from 1 to 16384)?1000

这些槽点分配给那个节点ID
8007节点ID 可以
通过 cluster nodes

 ./redis-cli -a root -c -h 192.168.217.128 -p 8001
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.217.128:8001> cluster nodes
8159431d3d56956ddc819584ff5526484a3f2705 192.168.217.128:8007@18007 master - 0 1624698771784 7  0 1624698770000 0 connected
160224afce6c868c653d8e26e0cc5bdaf8da17be 192.168.217.130:8003@18003 master - 0 1624698769752 3 connected 11122-16383
0f3e37ec085d26448898129af9388f1a74a2c19e 192.168.217.130:8006@18006 slave 736fe6711ab1c1abfaace923fa553661bf956c37 0 1624698769042 6 connected
02d47d69650337ec4a967f5311718939c65d61ee 192.168.217.128:8001@18001 myself,master - 0 1624698769000 1 connected 199-5460
1e10e6ac6562918ee95480feb7a48e4679c3db62 192.168.217.128:8004@18004 slave 160224afce6c868c653d8e26e0cc5bdaf8da17be 0 1624698772807 4 connected

What is the receiving node ID?8159431d3d56956ddc819584ff5526484a3f2705

在Source node 1:输入 all
Source node 1:all

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

Do you want to proceed with the proposed reshard plan (yes/no)? yes

完成 后 再查看集群状态信息

./redis-cli -a root -c -h 192.168.217.128 -p 8001

 cluster nodes

为 8007 添加 slave

./redis-cli -a root --cluster add-node 192.168.217.128:8008 192.168.217.128:8001

查看新增的8008 节点信息

 ./redis-cli -a root -c -h 192.168.217.128 -p 8001
 
cluster nodes

记录8007 节点信息

8159431d3d56956ddc819584ff5526484a3f2705 192.168.217.128:8007@18007 master

将 8008 添加到8007 成为 8007 的slave;链接到 8008 节点 设置 为8007 的集群slave

./redis-cli -a root -c -h 192.168.217.128 -p 8008

cluster replicate 8159431d3d56956ddc819584ff5526484a3f2705

删除节点
用del-node删除从节点8008

./redis-cli -a admin21262  --cluster del-node 192.168.217.128:8008 0d62b7a164159c5a0a3cf72074a1b14b7c2f43ff

>>> Removing node 0d62b7a164159c5a0a3cf72074a1b14b7c2f43ff from cluster 192.168.217.128:8008
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

删除8007 主节点,删除前先将8007 主节点的槽中的数据转移到其他主节点中

./redis-cli -a admin21262  --cluster reshard 192.168.217.128:8007

根据提示将8007 的槽移动到其他主节点

How many slots do you want to move (from 1 to 16384)?1000

输入8001 节点ID
What is the receiving node ID?02d47d69650337ec4a967f5311718939c65d61ee

从8007 迁移 输入 8001 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:8159431d3d56956ddc819584ff5526484a3f2705
这个提示 输入 done完成即可

Source node 2:done
这个迁移计划提示 输入yes 
Do you want to proceed with the proposed reshard plan (yes/no)? yes
./redis-cli -a root --cluster reshard 192.168.217.128:8007
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.217.128:8007)
M: 8159431d3d56956ddc819584ff5526484a3f2705 192.168.217.128:8007
   slots:[0-198],[5461-5661],[10923-11121] (599 slots) master
M: 02d47d69650337ec4a967f5311718939c65d61ee 192.168.217.128:8001
   slots:[199-5460] (5262 slots) master
   1 additional replica(s)
M: 736fe6711ab1c1abfaace923fa553661bf956c37 192.168.217.129:8002
   slots:[5662-10922] (5261 slots) master
   1 additional replica(s)
S: 1e10e6ac6562918ee95480feb7a48e4679c3db62 192.168.217.128:8004
   slots: (0 slots) slave
   replicates 160224afce6c868c653d8e26e0cc5bdaf8da17be
S: 0f3e37ec085d26448898129af9388f1a74a2c19e 192.168.217.130:8006
   slots: (0 slots) slave
   replicates 736fe6711ab1c1abfaace923fa553661bf956c37
S: 7952c769a0adb08753554e8767fdd415ed7a4e43 192.168.217.129:8005
   slots: (0 slots) slave
   replicates 02d47d69650337ec4a967f5311718939c65d61ee
M: 160224afce6c868c653d8e26e0cc5bdaf8da17be 192.168.217.130:8003
   slots:[11122-16383] (5262 slots) master
   1 additional replica(s)
[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)? 1000
What is the receiving node ID? 02d47d69650337ec4a967f5311718939c65d61ee
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: 8159431d3d56956ddc819584ff5526484a3f2705
Source node #2: done

Ready to move 1000 slots.
  Source nodes:
    M: 8159431d3d56956ddc819584ff5526484a3f2705 192.168.217.128:8007
       slots:[0-198],[5461-5661],[10923-11121] (599 slots) master
  Destination node:
    M: 02d47d69650337ec4a967f5311718939c65d61ee 192.168.217.128:8001
       slots:[199-5460] (5262 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 0 from 8159431d3d56956ddc819584ff5526484a3f2705
    .......
    Do you want to proceed with the proposed reshard plan (yes/no)? yes

迁移完成 然后再使用用del-node命令删除8007主节点即

./redis-cli -a admin21262  --cluster del-node 192.168.217.128:8007 8159431d3d56956ddc819584ff5526484a3f2705

done…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值