redis cluster 4.0.9 之四: 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实例

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:7001,192.168.0.103:7001
192.168.0.102:7000 > 192.168.0.101:7002,192.168.0.103:7002
192.168.0.103:7000 > 192.168.0.101:7001,192.168.0.102:7002

redis-trib.rb add-node

node1、node2、node3 节点创建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

node1 节点上操作

# /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

第一个参数为待添加的新节点,第二个参数为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 .需要添加参数 –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:7001,192.168.0.103:7001
192.168.0.102:7000 > 192.168.0.101:7002,192.168.0.103:7002
192.168.0.103:7000 > 192.168.0.101:7001,192.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)
   

此时的状况是虽然成功添加了1个master,2个salve,但是并没有分配slots。

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

你可能感兴趣的:(#,redis,setup,cluster,redis-trib.rb,redis-trib,redis-server)