1. 程式人生 > >redis linux-叢集新增刪除節點流程

redis linux-叢集新增刪除節點流程

一。新增主節點

開啟/usr/local/redis-3.2.7/cluster

        mkdir 6385

    #複製redis.conf配置檔案並把埠改成6385

啟動新增節點:./redis-server /usr/local/redis-3.2.7/cluster/6385/redis.conf

檢視節點ps -ef | grep redis

新增節點

 開啟/usr/local/redis-3.2.7/src執行./redis-trib.rb add-node 127.0.0.1:6385 127.0.0.1:6384

127.0.0.1:6385為新增節點

127.0.0.1:6384為已有叢集中任何節點

出現以下資訊表示新增成功

[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 120.77.61.47:6385 to make it join the cluster.
[OK] New node added correctly.

檢視新節點狀態:./redis-trib.rb check 127.0.0.1:6385

重新分配slots

./redis-trib.rb reshard 127.0.0.1:6384

127.0.0.1:6384為叢集中任意節點

出現How many slots do you want to move (from 1 to 16384)?   時我們有4個master就平均分配輸入16384/4=4096

出現What is the receiving node ID? 輸入6835的id:ee3efb90e5ac0725f15238a64fc60a18a71205d7

出現Source node #1:時,如果不指定特定id直接輸入all從所有節點中抽取

確認分配後結果:./redis-trib.rb check 127.0.0.1:6385

看到slots分配完畢這新增結束

二。新增從節點

開啟/usr/local/redis-3.2.7/cluster

        mkdir 6386

    #複製redis.conf配置檔案並把埠改成6386

啟動新增節點:./redis-server /usr/local/redis-3.2.7/cluster/6386/redis.conf

檢視節點ps -ef | grep redis

新增節點

 開啟/usr/local/redis-3.2.7/src執行./redis-trib.rb add-node --slave 127.0.0.1:6386  127.0.0.1:6385

127.0.0.1:6386 為從節點

127.0.0.1:6385為要新增到的目標主節點

出現以下資訊表示成功

[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Automatically selected master 127.0.0.1:6385
>>> Send CLUSTER MEET to node 127.0.0.1:6386 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 127.0.0.1:6385.
[OK] New node added correctly.

檢視結果./redis-trib.rb check 127.0.0.1:6386

三.刪除節點(刪除順序是先刪從節點再刪除主節點)

   刪除從節點./redis-trib.rb del-node 127.0.0.1:6386 b51de0185386c80b73fbe87a68b1b580bb558b4e

>>> Removing node b51de0185386c80b73fbe87a68b1b580bb558b4e from cluster 127.0.0.1:6386
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

檢視結果./redis-trib.rb check 127.0.0.1:6385發現已經沒有6386節點

 刪除主節點:(因為在主節點中存放著資料,所以我們在刪除之前,要把這些資料遷移走,並且把該節點上的雜湊槽分配到其他主節點上)

移動雜湊槽./redis-trib.rb reshard 127.0.0.1:6385

出現How many slots do you want to move (from 1 to 16384)? 由於6385上有4096個槽所以輸入4096全部移除

出現What is the receiving node ID?選擇要移動到的主節點

Source node #1:03ccad2ba5dd1e062464bc7590400441fafb63f2 //被刪除master的node-id  
Source node #2:done 

檢視結果./redis-trib.rb check 127.0.0.1:6385如果沒有雜湊槽就執行下一步

執行:./redis-trib.rb del-node 127.0.0.1:6385 61f786c40bcc170006a440abd7dc773e6dd15a19

檢視結果./redis-trib.rb check 127.0.0.1:6385發現已經沒有6385節點

錯誤處理:

[WARNING] Node 120.77.61.47:6379 has slots in migrating state (2156).
[WARNING] Node 120.77.61.47:6380 has slots in importing state (2156).
[WARNING] The following slots are open: 2156

使用./redis-trib.rb fix ./redis-trib.rb fix 127.0.0.1:6380修復

可以登入到相應的節點./redis-cli -h 127.0.0.1 -p 6380,使用命令“cluster setslot 2156 stable”修改,引數2156為問題顯示的slot的ID