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

os: ubuntu 16.04
redis:4.0.9
ruby:2.4.4

<> 添加好 master 和 slave 后,就要 reblance slots.

redis-trib.rb reshard

现在手动重新分配 slots

# /usr/redis/redis-4.0.9/src/redis-trib.rb
  reshard         host:port
                  --from 
                  --to 
                  --slots 
                  --yes
                  --timeout 
                  --pipeline 
# /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

你可能感兴趣的:(#,redis,setup,cluster)