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


發佈了20 篇原創文章 · 獲贊 5 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章