redis集羣擴容

redis集羣擴容

一:擴容須要考慮的問題node

1.遷移時槽的數據會不會遷過去redis

2.遷移過程集羣讀寫受影響嗎ide

3.須要限速嗎設計

4.如何確保遷移後的完整性server

二:如何設計擴容確保遷移過程當中數據不會受影響?blog

1.遷移過程當中,一個窗口讀數據,一個窗口寫數據get

2.觀察是否會中斷hash

三:建立新的節點it

mkdir -p /opt/redis_{6390,6391}/{conf,logs,pid}class

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

 

相關文章
相關標籤/搜索