手動擴(kuò)容
1、添加新節(jié)點到集群
./redis-cli -a xxx --cluster add-node newIP:newPort oldIP:oldPort
2、設(shè)置新節(jié)點主從關(guān)系
redis-cli -h 10.2.19.213 -p 6383 -a xxxx cluster replicate masterID
3、單個節(jié)點slot負(fù)載均衡
./redis-cli -a 密碼 --cluster reshard oldIP:oldPort
自動擴(kuò)容
1、添加新節(jié)點到集群
./redis-cli -a xxx --cluster add-node newIP:newPort oldIP:oldPort
2、設(shè)置新節(jié)點主從關(guān)系
redis-cli -h 10.2.19.213 -p 6383 -a xxxx cluster replicate masterID
3、所有節(jié)點,一次性reblance
--cluster-simulate 預(yù)估遷移槽位,不真正執(zhí)行。
--cluster-pipeline 50 建議每次遷移50個key,以往這個數(shù)量很平穩(wěn)
--cluster-use-empty-masters 重新平方slot時,包含沒有slot 的節(jié)點
./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節(jié)點
./redis-cli -a xxxx --cluster del-node 10.2.324.28:6380 待刪除節(jié)點ID
2、如果是主節(jié)點,將slot遷移到其他節(jié)點。
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
# 解決辦法
把目標(biāo)節(jié)點的slot 刪除
redis-cli -h 10.2.68.324 -p 6391 -a 密碼 cluster delslots 0
slot 在migrating狀態(tài),需要關(guān)閉
>>> 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集群,在擴(kuò)容時報錯,最終選擇redis-shake遷移到新集群
當(dāng)源端一次執(zhí)行多個key時,不在同一個slot中,會導(dǎo)致擴(kuò)容的失敗
CROSSSLOT Keys in request don't hash to the same slot