一:扩容需要考虑的问题
1.迁移时槽的数据会不会迁过去
2.迁移过程集群读写受影响吗
3.需要限速吗
4.如何确保迁移后的完整性
二:如何设计扩容确保迁移过程中数据不会受影响?
1.迁移过程中,一个窗口读数据,一个窗口写数据
2.观察是否会中断
三:创建新的节点
mkdir -p /opt/redis_{6390,6391}/{conf,logs,pid}
mkdir -p /data/redis_{6390,6391}
cd /opt/
cp redis_6380/conf/redis_6380.conf redis_6390/conf/redis_6390.conf
cp redis_6380/conf/redis_6380.conf redis_6391/conf/redis_6391.conf
sed -i ‘s#6380#6390#g‘ redis_6390/conf/redis_6390.conf
sed -i ‘s#6380#6391#g‘ redis_6391/conf/redis_6391.conf
redis-server /opt/redis_6390/conf/redis_6390.conf
redis-server /opt/redis_6391/conf/redis_6391.conf
ps -ef|grep redis
redis-cli -c -h 10.0.0.101 -p 6380 cluster meet 10.0.0.101 6390
redis-cli -c -h 10.0.0.101 -p 6380 cluster meet 10.0.0.101 6391
redis-cli -c -h 10.0.0.101 -p 6380 cluster nodes
四:扩容步骤
#重新分配槽位
redis-cli --cluster reshard 10.0.0.101:6380
#第一次交互:每个节点最终分配多少个槽
How many slots do you want to move (from 1 to 16384)? 4096
#第二次交互:接受节点的ID
What is the receiving node ID? 6390的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
#验证迁移数据的过程中数据是否会中断
写命令
for i in {1..1000};do redis-cli -c -h 10.0.0.101 -p 6380 set k_${i} v_${i} && echo ${i} is ok;sleep 0.5;done
读命令
for i in {1..1000};do redis-cli -c -h 10.0.0.101 -p 6380 get k_${i};sleep 0.5;done
#检查扩容后集群状态
redis-cli --cluster info 10.0.0.101:6380