標籤:
在Redis 3.0叢集(一)中講了Redis叢集的基本搭建。這一節主要講對Redis叢集的操作。
添加Master節點到叢集
redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000
node:新節點沒有包含任何資料, 因為它沒有包含任何slot。新加入的加點是一個主節點, 當叢集需要將某個從節點升級為新的主節點時, 這個新節點不會被選中。
redis-trib.rb reshard 127.0.0.1:7000#根據提示選擇要遷移的slot數量(ps:這裡選擇500)How many slots do you want to move (from 1 to 16384)? 500#選擇要接受這些slot的node-idWhat is the receiving node ID? f51e26b5d5ff74f85341f06f28f125b7254e61bf#選擇slot來源:#all表示從所有的master重新分配,#或者資料要提取slot的master節點id,最後用done結束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:3375be2ccc321932e8853234ffa87ee9fde973ffSource node #2:done#列印被移動的slot後,輸入yes開始移動slot以及對應的資料.#Do you want to proceed with the proposed reshard plan (yes/no)? yes#結束
redis-cli -c -p 7000cluster nodes
可以看到返回的叢集資訊中,7006擁有了0-999雜湊槽。
添加Slave節點到叢集
redis-trib.rb add-node 127.0.0.1:7007 127.0.0.1:7000
redis-cli -c -p 7007#參數為master節點的IDcluster replicate 2b9ebcbd627ff0fd7a7bbcc5332fb09e72788835
刪除一個Slave節點
#redis-trib del-node ip:port ‘<node-id>‘ redis-trib.rb del-node 127.0.0.1:7007 ‘c7ee2fca17cb79fe3c9822ced1d4f6c5e169e378‘
刪除一個Master節點
刪除master節點之前首先要使用reshard移除master的全部slot,然後再刪除當前節點(目前只能把被刪除master的slot遷移到一個節點上)
redis-trib.rb reshard 127.0.0.1:7006#根據提示選擇要遷移的slot數量(ps:這裡選擇500)How many slots do you want to move (from 1 to 16384)? 500#選擇要接受這些slot的node-idWhat is the receiving node ID? f51e26b5d5ff74f85341f06f28f125b7254e61bf#選擇slot來源:#all表示從所有的master重新分配,#或者資料要提取slot的master節點id,最後用done結束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:3375be2ccc321932e8853234ffa87ee9fde973ffSource node #2:done#列印被移動的slot後,輸入yes開始移動slot以及對應的資料.#Do you want to proceed with the proposed reshard plan (yes/no)? yes#結束#刪除空master節點redis-trib.rb del-node 127.0.0.1:7006 ‘c7ee2fca17cb79fe3c9822ced1d4f6c5e169e378‘
Redis 3.0叢集(二)