centos7 redis叢集增減節點
redis現在叢集環境:
192.168.2.41 7000 7001
192.168.2.42 7002 7003
192.168.2.43 7004 7005
經過變更之後的叢集環境:
192.168.2.41 7000 7001
192.168.2.42 7000 7001
192.168.2.43 7000 7001
且各臺的7000為master,7001是各臺機器7000的slave
1、刪除slave節點
檢視叢集資訊
# redis-trib.rb check 192.168.2.41:7000
slave節點可以直接刪除
命令
redis-trib.rb del-node IP:PORT ID
# redis-trib.rb del-node 192.168.2.41:7001 a123f3ec62c8367f396a1fef8ae9c6c0ac413d96
# redis-trib.rb del-node 192.168.2.42:7003 17d25af071d0f5508e2d3bfae9d6b4322ad2f5f5
# redis-trib.rb del-node 192.168.2.43:[email protected] eb2b9276976ea162473f8ce00b2c8c35785721c9
2、刪除master節點
刪除master節點需要首先把其上slots進行轉移
這裡的192.168.2.41的master節點不進行刪除,刪除叢集中的其他兩個master
首先要把192.168.2.42:7002和192.168.2.43:7004的slots轉移到192.168.2.41:7000上
檢視叢集資訊,可以檢視到節點有多少slots,有多少就需要轉移多少
命令:
redis-trib.rb reshard IP:PORT
# redis-trib.rb reshard 192.168.2.42:7002
How many slots do you want to move (from 1 to 16384)? 5461
What is the receiving node ID? 9226e25993d0e6cc75600bb6ad21f01090746fd7
Source node #1:4bd00c217e74513f202982458f5fb699771dee55
Source node #2:done
說明:
第一個為要轉移的slots的個數,按實際情況填寫
第二個為要轉移到的節點的節點id
第三個為要轉移slots的節點的節點id
# redis-trib.rb reshard 192.168.2.43:7004
刪除兩個master節點
# redis-trib.rb del-node 192.168.2.42:7002 4bd00c217e74513f202982458f5fb699771dee55
# redis-trib.rb del-node 192.168.2.43:7004 1b13f21a02938c739f29dcd803886379054bf793
3、修改配置檔案
修改刪除的四個節點的配置檔案
分別是
192.168.2.42:7002
192.168.2.42:7003
192.168.2.43:7004
192.168.2.43:7005
以192.168.2.42:7002為例
# cd /usr/local/redis-4.0.11/cluster
# mv 7002 7000
# mv 7003 7001
# sed -i 's/7002/7000/g' 7000/redis.conf
# sed -i 's/7003/7001/g' 7001/redis.conf
其他三個節點以此類推做修改
4、啟動服務
192.168.2.41
# redis-server /usr/local/redis-4.0.11/cluster/7001/redis.conf
192.168.2.42
# redis-server /usr/local/redis-4.0.11/cluster/7000/redis.conf
# redis-server /usr/local/redis-4.0.11/cluster/7001/redis.conf
192.168.2.43
# redis-server /usr/local/redis-4.0.11/cluster/7000/redis.conf
# redis-server /usr/local/redis-4.0.11/cluster/7001/redis.conf
5、增加master節點
命令:
redis-trib.rb add-node ADD-NODEIP:PORT ADD-TO-NODEIP:PORT
# redis-trib.rb add-node 192.168.2.42:7000 192.168.2.41:7000
# redis-trib.rb add-node 192.168.2.43:7000 192.168.2.41:7000
6、增加slave節點
命令:
redis-trib.rb add-node --slave SLAVENODEIP:PORT MASTERNODEIP:PORT
# redis-trib.rb add-node --slave 192.168.2.41:7001 192.168.2.41:7000
# redis-trib.rb add-node --slave 192.168.2.42:7001 192.168.2.42:7000
# redis-trib.rb add-node --slave 192.168.2.43:7001 192.168.2.43:7000
7、轉移slots到其他兩個新增的master
檢視叢集資訊
# redis-trib.rb check 192.168.2.41:7000
>>> Performing Cluster Check (using node 192.168.2.41:7000)
M: 9226e25993d0e6cc75600bb6ad21f01090746fd7 192.168.2.41:7000
slots:10922-16383 (5462 slots) master
1 additional replica(s)
S: b79bf8001cff43a5df16b285ecbc9caccf8b12ef 192.168.2.41:7001
slots: (0 slots) slave
replicates 9226e25993d0e6cc75600bb6ad21f01090746fd7
M: 174b6d42aa784e69a3104f6f06574919cb69d7d8 192.168.2.42:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: a06342821949f7d666fe5d7b5b64d4573c33c8ea 192.168.2.42:7001
slots: (0 slots) slave
replicates 174b6d42aa784e69a3104f6f06574919cb69d7d8
M: 5fb1b9ca8da83af089fa8f022abf13d2041d6d60 192.168.2.43:7000
slots:5461-10921 (5461 slots) master
1 additional replica(s)
S: b5ef76db06606ffb36cd3ee22570dfd7e14c5a33 192.168.2.43:7001
slots: (0 slots) slave
replicates 5fb1b9ca8da83af089fa8f022abf13d2041d6d60
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.