redis cluster 4.0.9の4:redis-trib.rb add-node


os: ubuntu 16.04 redis:4.0.9 ruby:2.4.4
ip計画
192.168.0.101 7000,7001,7002
192.168.0.102 7000,7001,7002
192.168.0.103 7000,7001,7002


次にredisインスタンスを3つ追加します
192.168.0.101 7003
192.168.0.102 7003
192.168.0.103 7003


参照<>では、ubuntu 16.04にredis cluster 4.0.9がインストールされており、詳細は省略されています.
# apt install make gcc g++ openssl libcurl4-openssl-dev zlib1g zlib1g-dev \
tcl tcl-dev iftop sysstat telnet tree curl lrzsz \
ruby ruby-dev libruby rubygems-integration

# gem install redis

次に、redisインスタンスを追加する手順を簡単に記録します.
redis-trib.rb check
# /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: bae1665a3a55f5f2f2c224e1533118a1168b6a1d 192.168.0.101:7000
   slots:0-5460 (5461 slots) master
   2 additional replica(s)
M: fbf3b7827137251d03638436d28a2a9b82cea44c 192.168.0.102:7000
   slots:5461-10922 (5462 slots) master
   2 additional replica(s)
S: f5a34cea79ae1614241eb489808b9309514fa8eb 192.168.0.101:7002
   slots: (0 slots) slave
   replicates fbf3b7827137251d03638436d28a2a9b82cea44c
S: 550f9347512ee841cf558ef254dbdf3b4379f6a9 192.168.0.103:7001
   slots: (0 slots) slave
   replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
M: ca76bd2110000f6285360e1d0979ac14fec7f86a 192.168.0.103:7000
   slots:10923-16383 (5461 slots) master
   2 additional replica(s)
S: d93a37d9fb2e526d01a5f4c6b6b9743674656286 192.168.0.101:7001
   slots: (0 slots) slave
   replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 464b9cab8863085b4bff880eca339a9e7983898c 192.168.0.103:7002
   slots: (0 slots) slave
   replicates fbf3b7827137251d03638436d28a2a9b82cea44c
S: bcdecbdb2528f2953145aa08c82d8c4a9a89e0a0 192.168.0.102:7002
   slots: (0 slots) slave
   replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 141c2cf5b07da8c0d5b4b7c6dc42335d7638946f 192.168.0.102:7001
   slots: (0 slots) slave
   replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
[OK] All nodes agree about slots configurat./7003/redis.confion.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

基本状況は、192.168.0.101:7000>192.168.0.102:700192.168.0.103:7001 192.168.0.102:7001 192.168.0.102:7000>192.168.0.101:7002192.168.0.103:7002 192.168.0.103:7000>192.168.0.101:70011192.168.0.102:7002
redis-trib.rb add-node
Node 1、node 2、node 3ノード作成7003
# cd /var/lib/redis/4.0.9/cluster-data
# cp -r ./7000 ./7003
# sed -i "s/7000/7003/g" ./7003/redis.conf
# rm ./7003/appendonly.aof ./7003/cluster_7000.conf ./7003/dump.rdb
# /usr/local/bin/redis-server /var/lib/redis/4.0.9/cluster-data/7003/redis.conf


Node 1ノードでの操作
# /usr/redis/redis-4.0.9/src/redis-trib.rb
  add-node        new_host:new_port existing_host:existing_port
                  --slave
                  --master-id 
# /usr/redis/redis-4.0.9/src/redis-trib.rb add-node 192.168.0.101:7003 192.168.0.101:7000


1番目のパラメータは追加する新しいノードであり、2番目のパラメータはclusterのいずれかのノードである.
ここでexisting_host:existing_portは、任意のredisインスタンスnew_host:new_port = 192.168.0.101:7003 existing_host:existing_port = 192.168.0.101:7000
# /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: bae1665a3a55f5f2f2c224e1533118a1168b6a1d 192.168.0.101:7000
   slots:0-5460 (5461 slots) master
   2 additional replica(s)
M: fbf3b7827137251d03638436d28a2a9b82cea44c 192.168.0.102:7000
   slots:5461-10922 (5462 slots) master
   2 additional replica(s)
S: f5a34cea79ae1614241eb489808b9309514fa8eb 192.168.0.101:7002
   slots: (0 slots) slave
   replicates fbf3b7827137251d03638436d28a2a9b82cea44c
S: 550f9347512ee841cf558ef254dbdf3b4379f6a9 192.168.0.103:7001
   slots: (0 slots) slave
   replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
M: ca76bd2110000f6285360e1d0979ac14fec7f86a 192.168.0.103:7000
   slots:10923-16383 (5461 slots) master
   2 additional replica(s)
S: d93a37d9fb2e526d01a5f4c6b6b9743674656286 192.168.0.101:7001
   slots: (0 slots) slave
   replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 464b9cab8863085b4bff880eca339a9e7983898c 192.168.0.103:7002
   slots: (0 slots) slave
   replicates fbf3b7827137251d03638436d28a2a9b82cea44c
M: 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.101:7003
   slots: (0 slots) master
   0 additional replica(s)
S: bcdecbdb2528f2953145aa08c82d8c4a9a89e0a0 192.168.0.102:7002
   slots: (0 slots) slave
   replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 141c2cf5b07da8c0d5b4b7c6dc42335d7638946f 192.168.0.102:7001
   slots: (0 slots) slave
   replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

# /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 | 5462 slots | 2 slaves.
192.168.0.103:7000 (ca76bd21...) -> 0 keys | 5461 slots | 2 slaves.
192.168.0.101:7003 (4a77a013...) -> 0 keys | 0 slots | 0 slaves.
[OK] 1 keys in 4 masters.
0.00 keys per slot on average.


さっき新しく追加したノードはmasterでslaveはありません
M: 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.101:7003
   slots: (0 slots) master
   0 additional replica(s)
   

192.168.0.101:7003にslaveを2つ追加します.パラメータを追加する必要があります-slave--master-id
# /usr/redis/redis-4.0.9/src/redis-trib.rb add-node --slave --master-id 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.102:7003 192.168.0.101:7003
# /usr/redis/redis-4.0.9/src/redis-trib.rb add-node --slave --master-id 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.103:7003 192.168.0.101:7003

# /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: bae1665a3a55f5f2f2c224e1533118a1168b6a1d 192.168.0.101:7000
   slots:0-5460 (5461 slots) master
   2 additional replica(s)
M: fbf3b7827137251d03638436d28a2a9b82cea44c 192.168.0.102:7000
   slots:5461-10922 (5462 slots) master
   2 additional replica(s)
S: f5a34cea79ae1614241eb489808b9309514fa8eb 192.168.0.101:7002
   slots: (0 slots) slave
   replicates fbf3b7827137251d03638436d28a2a9b82cea44c
S: b7ee4163c0d14e7c763a2c4072f10042c84e4ca6 192.168.0.103:7003
   slots: (0 slots) slave
   replicates 4a77a0134068e2d9f2734213ead14bf9bce2e072
S: 550f9347512ee841cf558ef254dbdf3b4379f6a9 192.168.0.103:7001
   slots: (0 slots) slave
   replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
M: ca76bd2110000f6285360e1d0979ac14fec7f86a 192.168.0.103:7000
   slots:10923-16383 (5461 slots) master
   2 additional replica(s)
S: 179d2cc1d16d59c479df8536e7720977772e75c8 192.168.0.102:7003
   slots: (0 slots) slave
   replicates 4a77a0134068e2d9f2734213ead14bf9bce2e072
S: d93a37d9fb2e526d01a5f4c6b6b9743674656286 192.168.0.101:7001
   slots: (0 slots) slave
   replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 464b9cab8863085b4bff880eca339a9e7983898c 192.168.0.103:7002
   slots: (0 slots) slave
   replicates fbf3b7827137251d03638436d28a2a9b82cea44c
M: 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.101:7003
   slots: (0 slots) master
   2 additional replica(s)
S: bcdecbdb2528f2953145aa08c82d8c4a9a89e0a0 192.168.0.102:7002
   slots: (0 slots) slave
   replicates ca76bd2110000f6285360e1d0979ac14fec7f86a
S: 141c2cf5b07da8c0d5b4b7c6dc42335d7638946f 192.168.0.102:7001
   slots: (0 slots) slave
   replicates bae1665a3a55f5f2f2c224e1533118a1168b6a1d
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

# /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 | 5462 slots | 2 slaves.
192.168.0.103:7000 (ca76bd21...) -> 0 keys | 5461 slots | 2 slaves.
192.168.0.101:7003 (4a77a013...) -> 0 keys | 0 slots | 2 slaves.
[OK] 1 keys in 4 masters.
0.00 keys per slot on average.


現在の基本状況は、192.168.0.101:7000>192.168.0.102:700192.168.0.103:7001 192.168.0.102:7001 192.168.0.102:7000>192.168.0.101:7002192.168.0.103:7002 192.168.0.103:7000>192.168.0.101:700192.168.0.102:7002
192.168.0.101:7003 > 192.168.0.102:7003,192.168.0.103:7003
注意観察、新しいmaster 192.168.0.101:7003はslotsを割り当てていません
M: 4a77a0134068e2d9f2734213ead14bf9bce2e072 192.168.0.101:7003
   slots: (0 slots) master
   2 additional replica(s)
   

この場合,master 1個,salve 2個の追加に成功したが,slotsは割り当てられなかった.
参照先:http://www.cnblogs.com/chenmh/p/9221672.html http://www.redis.cn/topics/cluster-tutorial.html