redis-cluster添加删除节点步骤

1、现有redis-cluster集群

三主三从

[root@localhost conf]# redis-trib.rb add-node 192.168.189.10:7000 192.168.189.10:6999
>>> Adding node 192.168.189.10:7000 to cluster 192.168.189.10:6999
>>> Performing Cluster Check (using node 192.168.189.10:6999)
M: f1d9a391a398a4116523b2e2cc40b8f54512312e 192.168.189.10:6999
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: f4937416e175a44c803bc08f583e085b78c903ed 192.168.189.30:26999
   slots: (0 slots) slave
   replicates 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b
M: 042536be1e4f7e9cc52d5809daabbccf77353f7a 192.168.189.20:6999
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b 192.168.189.30:6999
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 1a8d0b1ce3e0d3b2ae9415c7f532ee85ceaf898c 192.168.189.10:26999
   slots: (0 slots) slave
   replicates 042536be1e4f7e9cc52d5809daabbccf77353f7a
S: 9a723a307d648f946aff2af54988b46e7566682f 192.168.189.20:26999
   slots: (0 slots) slave
   replicates f1d9a391a398a4116523b2e2cc40b8f54512312e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

2、添加两组redis实例

作为redis-cluster的一个主节点一个从节点,修改端口信息

cp redis_6999.conf redis_7000.conf
cp redis_6999.conf redis_7001.conf

3、添加master节点

添加master

redis-trib.rb  add-node  new_host:new_port existing_host:existing_port

eq:

redis-trib.rb add-node 192.168.189.10:7000 192.168.189.10:6999

new_host:new_port新的master节点IP+端口
existing_host:existing_port原集群任意节点的IP+端口
成功添加:

[root@localhost conf]# redis-trib.rb add-node 192.168.189.10:7000 192.168.189.10:6999
>>> Adding node 192.168.189.10:7000 to cluster 192.168.189.10:6999
>>> Performing Cluster Check (using node 192.168.189.10:6999)
M: f1d9a391a398a4116523b2e2cc40b8f54512312e 192.168.189.10:6999
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: f4937416e175a44c803bc08f583e085b78c903ed 192.168.189.30:26999
   slots: (0 slots) slave
   replicates 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b
M: 042536be1e4f7e9cc52d5809daabbccf77353f7a 192.168.189.20:6999
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b 192.168.189.30:6999
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 1a8d0b1ce3e0d3b2ae9415c7f532ee85ceaf898c 192.168.189.10:26999
   slots: (0 slots) slave
   replicates 042536be1e4f7e9cc52d5809daabbccf77353f7a
S: 9a723a307d648f946aff2af54988b46e7566682f 192.168.189.20:26999
   slots: (0 slots) slave
   replicates f1d9a391a398a4116523b2e2cc40b8f54512312e
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.189.10:7000 to make it join the cluster.
[OK] New node added correctly.

分配插槽

redis-trib.rb reshard 命令连接任意节点:

redis-trib.rb reshard 192.168.189.10:7000

需要移动的插槽数:

M: 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b 192.168.189.30:6999
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 1000
What is the receiving node ID? 3dd66b26a1e16fad114456ca31b210ffe8539dea
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

How many slots do you want to move (from 1 to 16384)?
需要分配的插槽数,需要手动输入
What is the receiving node ID?
需要接受的节点ID,手动输入
Source node #1:
all 从所有master节点转移插槽数
done:从某一个master节点中取插槽,最后用done结束

查看新的master

[root@localhost conf]# redis-trib.rb check 192.168.189.10:7000
>>> Performing Cluster Check (using node 192.168.189.10:7000)
M: 3dd66b26a1e16fad114456ca31b210ffe8539dea 192.168.189.10:7000
   slots:0-332,5461-5794,10923-11255 (1000 slots) master
   0 additional replica(s)

添加从节点

添加为从节点,并指定主节点
redis-trib.rb add-node --slave --master-id 刚才添加的masterID 新节点IP:端口 任意旧节点IP:端口

redis-trib.rb add-node --slave --master-id 3dd66b26a1e16fad114456ca31b210ffe8539dea 192.168.189.10:7001 192.168.189.10:6999

报错处理

分配槽时出现错误:

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

    Moving slot 11254 from 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b
    Moving slot 11255 from 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 5461 from 192.168.189.20:6999 to 192.168.189.10:7000:
[ERR] Calling MIGRATE: ERR Syntax error, try CLIENT (LIST | KILL | GETNAME | SETNAME | PAUSE | REPLY)

[root@localhost conf]# redis-trib.rb check 192.168.189.10:7000
>>> Performing Cluster Check (using node 192.168.189.10:7000)
M: 3dd66b26a1e16fad114456ca31b210ffe8539dea 192.168.189.10:7000
   slots: (0 slots) master
   0 additional replica(s)
S: 1a8d0b1ce3e0d3b2ae9415c7f532ee85ceaf898c 192.168.189.10:26999
   slots: (0 slots) slave
   replicates 042536be1e4f7e9cc52d5809daabbccf77353f7a
M: 042536be1e4f7e9cc52d5809daabbccf77353f7a 192.168.189.20:6999
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
M: f1d9a391a398a4116523b2e2cc40b8f54512312e 192.168.189.10:6999
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: f4937416e175a44c803bc08f583e085b78c903ed 192.168.189.30:26999
   slots: (0 slots) slave
   replicates 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b
S: 9a723a307d648f946aff2af54988b46e7566682f 192.168.189.20:26999
   slots: (0 slots) slave
   replicates f1d9a391a398a4116523b2e2cc40b8f54512312e
M: 0e91e7aa168e1b06987fecf568f0bf909fa9dd1b 192.168.189.30:6999
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
[WARNING] Node 192.168.189.10:7000 has slots in importing state (5461).
[WARNING] Node 192.168.189.20:6999 has slots in migrating state (5461).
[WARNING] The following slots are open: 5461
>>> Check slots coverage...
[OK] All 16384 slots covered.

解决:

[root@localhost conf]# gem list

*** LOCAL GEMS ***

bigdecimal (default: 1.2.8)
bundler (default: 1.17.3)
did_you_mean (1.0.0)
drydock (0.6.9)
gem-wrappers (1.4.0)
io-console (default: 0.4.5)
json (default: 1.8.3)
minitest (5.8.3)
net-telnet (0.1.1)
power_assert (0.2.6)
psych (default: 2.0.17)
rake (10.4.2)
rdoc (default: 4.2.1)
redis (4.2.5)
redis-dump (0.4.0)
test-unit (3.1.5)
uri-redis (0.4.2)
yajl-ruby (1.4.1)
[root@localhost conf]# gem uinstall redis
ERROR:  While executing gem ... (Gem::CommandLineError)
    Unknown command uinstall
[root@localhost conf]# gem uninstall redis

You have requested to uninstall the gem:
        redis-4.2.5

redis-dump-0.4.0 depends on redis (>= 4.0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN]  y
Successfully uninstalled redis-4.2.5
[root@localhost conf]# gem install redis -v 3.3.5
Fetching redis-3.3.5.gem
Successfully installed redis-3.3.5
Parsing documentation for redis-3.3.5
Installing ri documentation for redis-3.3.5
Done installing documentation for redis after 3 seconds
1 gem installed

连接到报错的节点,执行以下命令
>>> Check for open slots...
[WARNING] Node 192.168.189.10:7000 has slots in importing state (5461).
[WARNING] Node 192.168.189.20:6999 has slots in migrating state (5461).
[WARNING] The following slots are open: 5461
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@localhost conf]# redis-cli -h 192.168.189.10 -p 7000
192.168.189.10:7000> cluster setslot 5461 stable
OK
192.168.189.10:7000>
[root@localhost conf]# redis-cli -h 192.168.189.20 -p 6999
192.168.189.20:6999> cluster setslot 5461 stable
OK
192.168.189.20:6999>

再重新分配

删除从节点

直接删除
redis-trib.rb del-node 节点IP:端口 节点ID
五、删除master节点
1.删除master节点对应的slave节点

删除slave节点或者将slave节点指定给别的master

删除slave节点:
redis-trib.rb del-node slave节点IP:端口 slave节点nodeid

将slave节点指定给别的master:
redis-cli -h 192.168.189.10 -p 29999 -c
192.168.189.10:29999> cluster replicate 新master节点的nodeid

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值