redis cluster 4.0.9 之六: redis-trib.rb reshard

os: ubuntu 16.04
redis:4.0.9
ruby:2.4.4

<<redis cluster 4.0.9 之四: redis-trib.rb add-node>> 添加好 master 和 slave 後,就要 reblance slots.

redis-trib.rb reshard

現在手動重新分配 slots

# /usr/redis/redis-4.0.9/src/redis-trib.rb
  reshard         host:port
                  --from <arg>
                  --to <arg>
                  --slots <arg>
                  --yes
                  --timeout <arg>
                  --pipeline <arg>
# /usr/redis/redis-4.0.9/src/redis-trib.rb reshard 192.168.0.101:7003

其中 host:port 爲集羣中的任何一個實例即可。
下面爲 redis-trib.rb reshard 的一些輸入簡介,可以參考下。

How many slots do you want to move (from 1 to 16384)? 

表示移動多少個 slots,建議使用 16384/4=4096,這裏輸入4000

What is the receiving node ID? 

表示新master 192.168.0.101:7003 的 id,這裏輸入 4a77a0134068e2d9f2734213ead14bf9bce2e072

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,從所有節點上移動部分 slots 到新的master上。

    Moving slot 12253 from ca76bd2110000f6285360e1d0979ac14fec7f86a
    Moving slot 12254 from ca76bd2110000f6285360e1d0979ac14fec7f86a
    Moving slot 12255 from ca76bd2110000f6285360e1d0979ac14fec7f86a
Do you want to proceed with the proposed reshard plan (yes/no)?

輸入yes,確認用。

在遷移中碰到了如下錯誤

Moving slot 5798 from 192.168.0.102:7000 to 192.168.0.101:7003: 
[ERR] Calling MIGRATE: ERR Syntax error, try CLIENT (LIST | KILL | GETNAME | SETNAME | PAUSE | REPLY)

check 時有 WARNING 提示

# /usr/redis/redis-4.0.9/src/redis-trib.rb check 192.168.0.101:7000

>>> Check for open slots...
[WARNING] Node 192.168.0.102:7000 has slots in migrating state (5798).
[WARNING] Node 192.168.0.101:7003 has slots in importing state (5798).
[WARNING] The following slots are open: 5798

參考 http://www.cnblogs.com/chenmh/p/9221672.html 使用解決辦法2。

# redis-cli -h 192.168.0.101 -p 7003 -c
192.168.0.101:7003> cluster setslot 5798 stable
OK

# redis-cli -h 192.168.0.102 -p 7000 -c
192.168.0.102:7000> cluster setslot 5798 stable
OK
# /usr/redis/redis-4.0.9/src/redis-trib.rb fix 192.168.0.101:7003
# /usr/redis/redis-4.0.9/src/redis-trib.rb fix 192.168.0.102:7000

檢查

# /usr/redis/redis-4.0.9/src/redis-trib.rb check 192.168.0.101:7000
M: 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.101:7003
   slots:5461-5797 (337 slots) master
   2 additional replica(s)
   
# /usr/redis/redis-4.0.9/src/redis-trib.rb info 192.168.0.101:7000
192.168.0.101:7000 (bae1665a...) -> 0 keys | 5461 slots | 2 slaves.
192.168.0.102:7000 (fbf3b782...) -> 1 keys | 5125 slots | 2 slaves.
192.168.0.103:7000 (ca76bd21...) -> 0 keys | 5461 slots | 2 slaves.
192.168.0.101:7003 (4a77a013...) -> 0 keys | 337 slots | 2 slaves.
[OK] 1 keys in 4 masters.
0.00 keys per slot on average.

可以看到 192.168.0.101:7003 的slots遷移成功了一部分,再手動繼續遷移時依舊報錯。

Moving slot 5798 from 192.168.0.102:7000 to 192.168.0.101:7003: 
[ERR] Calling MIGRATE: ERR Syntax error, try CLIENT (LIST | KILL | GETNAME | SETNAME | PAUSE | REPLY)

後經過分析後發現是是使用gem 安裝的 redis 接口版本過高,隨後降級到版本 3.3.3

# ruby --version
ruby 2.4.4p296 (2018-03-28 revision 63013) [x86_64-linux]
# gem list |grep -i redis
redis (4.0.2)
# gem uninstall redis --version 4.0.2
# gem install redis -v 3.3.3

再次reshard 成功執行。


# /usr/redis/redis-4.0.9/src/redis-trib.rb check 192.168.0.101:7000
>>> Performing Cluster Check (using node 192.168.0.101:7000)
M: 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.101:7003
   slots:0-1971,5461-6895,10923-12893 (5378 slots) master
   2 additional replica(s)

參考:
http://www.cnblogs.com/chenmh/p/9221672.html
http://www.redis.cn/topics/cluster-tutorial.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章