手动扩容
1、添加新节点到集群
./redis-cli -a xxx --cluster add-node newIP:newPort oldIP:oldPort
2、设置新节点主从关系
redis-cli -h 10.2.19.213 -p 6383 -a xxxx cluster replicate masterID
3、单个节点slot负载均衡
./redis-cli -a 密码 --cluster reshard oldIP:oldPort
自动扩容
1、添加新节点到集群
./redis-cli -a xxx --cluster add-node newIP:newPort oldIP:oldPort
2、设置新节点主从关系
redis-cli -h 10.2.19.213 -p 6383 -a xxxx cluster replicate masterID
3、所有节点,一次性reblance
--cluster-simulate 预估迁移槽位,不真正执行。
--cluster-pipeline 50 建议每次迁移50个key,以往这个数量很平稳
--cluster-use-empty-masters 重新平方slot时,包含没有slot 的节点
./redis-cli -a xxxx --cluster rebalance --cluster-use-empty-masters --cluster-simulate --cluster-pipeline 50 10.2.321.149:6380
./redis-cli -a xxxx --cluster rebalance --cluster-use-empty-masters --cluster-pipeline 50 10.2.321.149:6380
缩容
1、剔除slave节点
./redis-cli -a xxxx --cluster del-node 10.2.324.28:6380 待删除节点ID
2、如果是主节点,将slot迁移到其他节点。
3、master没有slot时,也可以剔除。
常见问题
reshard 出错后,
[WARNING] Node 10.2.68.324:6391@16391 has slots in importing state (0).
[WARNING] Node 10.2.22.229:6380@16380 has slots in migrating state (0).
[WARNING] The following slots are open: 0
# 解决办法
把目标节点的slot 删除
redis-cli -h 10.2.68.324 -p 6391 -a 密码 cluster delslots 0
slot 在migrating状态,需要关闭
>>> Check for open slots...
[WARNING] Node 10.2.22.229:6380@16380 has slots in migrating state (0).
[WARNING] The following slots are open: 0
>>> Fixing open slot 0
Set as migrating in: 10.2.22.229:6380@16380
Set as importing in:
[ERR] Sorry, Redis-trib can't fix this slot yet (work in progress). Slot is set as migrating in 10.2.22.229:6380@16380, as importing in , owner is 10.2.22.229:6380@16380
>>> Check slots coverage...
[OK] All 16384 slots covered.
# 必须连接出问题的 端口
redis-cli -h 10.2.22.229 -p 6380 -a 密码 CLUSTER SETSLOT 0 STABLE
#遇到一次redis集群,在扩容时报错,最终选择redis-shake迁移到新集群
当源端一次执行多个key时,不在同一个slot中,会导致扩容的失败
CROSSSLOT Keys in request don't hash to the same slot
网友评论