在原集群中增加节点,再增加一主一从,在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 的集群复制
./redis-cli -a root -c -h 192.168.217.128 -p 8008
cluster replicate 8159431d3d56956ddc819584ff5526484a3f2705
./redis-cli -a admin21262 --cluster del-node 192.168.217.128:8008 0d62b7a164159c5a0a3cf72074a1b14b7c2f43ff
删除8007 主节点,删除前先将8007 主节点的槽中的数据转移到其他主节点中
./redis-cli -a admin21262 --cluster reshard 192.168.217.128
根据提示将8007 的槽移动到其他主节点
How many slots do you want to move (from 1 to 16384)?1000
输入8001 节点ID
What is the receiving node ID?02d47d69650337ec4a967f5311718939c65d61ee
从8007 迁移 输入 8007 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
这个提示 输入 node 完成即可
Source node 2:done
这个迁移计划提示 输入yes
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…
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。