欢迎阅读!

潇湘夜雨

当前位置: 主页 > 数据库 >

redis cluster集群配置和运维(3)

时间:2017-06-09 17:17来源:潇湘夜雨 作者:华嵩阳 点击:
[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.198.128:6382 to make it join the cluster
[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.198.128:6382 to make it join the cluster.
[OK] New node added correctly.
 
注意:新节点没有包含任何数据, 因为它没有包含任何slot。新加入的加点是一个主节点, 当集群需要将某个从节点升级为新的主节点时, 这个新节点不会被选中
 
127.0.0.1:6382> CLUSTER nodes #查看集群节点
8e2ad457f09186549b714c2260742773de1db658 192.168.198.130:5381 master - 0 1496913541568 10 connected 5461-10922
e97d65ce427e00b4ff89014dcdb05cfdad9f8152 192.168.198.128:6380 slave f4c656b100cc40650cbcbb266cb5523020fb4b38 0 1496913537024 4 connected
14cc31f74c23fa6b237334b11d984989c6d8cc4e 192.168.198.130:5380 master - 0 1496913542576 5 connected 10923-16383
659b9e99cfe7cfe198d10231bc4526a34c316cdc 192.168.198.128:6379 slave 8e2ad457f09186549b714c2260742773de1db658 0 1496913539546 10 connected
0ab74446f7052b1c681a2cce11f46298c5fa93bb 192.168.198.128:6382 myself,master - 0 0 0 connected
399cbff5edff7258081fd73f98a1cb2857cb9824 192.168.198.128:6381 slave 14cc31f74c23fa6b237334b11d984989c6d8cc4e 0 1496913540557 5 connected
f4c656b100cc40650cbcbb266cb5523020fb4b38 192.168.198.130:5379 master - 0 1496913537532 4 connected 0-5460
127.0.0.1:6382> set new 2
-> Redirected to slot [15045] located at 192.168.198.130:5380 #写入数据时会跳转到其它节点
OK
 
注意:虽然现在此新节点已经连到集群,并且可以重定向客户端到正确的集群节点了,但是它跟集群的其他主节点有个不同的地方:
*它没有数据,因为没有分配哈希槽给它
*因为它是一个没有哈希槽的主节点,当一个从节点需要被选举成新主节点时,它没有参与权
 
可以通过redis-trib的重新分片指令来给新节点增加哈希槽。
 
[root@localhost redis]# redis-trib.rb check 192.168.198.128:6382
>>> Performing Cluster Check (using node 192.168.198.128:6382)
M: 0ab74446f7052b1c681a2cce11f46298c5fa93bb 192.168.198.128:6382
  slots: (0 slots) master
  0 additional replica(s)
 
  
(3) 给新节点分配slots
[root@localhost redis]# redis-trib.rb reshard 192.168.198.128:6382
>>> Performing Cluster Check (using node 192.168.198.128:6382)
M: 0ab74446f7052b1c681a2cce11f46298c5fa93bb 192.168.198.128:6382
  slots: (0 slots) master
  0 additional replica(s)
M: 8e2ad457f09186549b714c2260742773de1db658 192.168.198.130:5381
  slots:5461-10922 (5462 slots) master
  1 additional replica(s)
S: e97d65ce427e00b4ff89014dcdb05cfdad9f8152 192.168.198.128:6380
  slots: (0 slots) slave
  replicates f4c656b100cc40650cbcbb266cb5523020fb4b38
M: 14cc31f74c23fa6b237334b11d984989c6d8cc4e 192.168.198.130:5380
  slots:10923-16383 (5461 slots) master
  1 additional replica(s)
S: 659b9e99cfe7cfe198d10231bc4526a34c316cdc 192.168.198.128:6379
  slots: (0 slots) slave
  replicates 8e2ad457f09186549b714c2260742773de1db658
S: 399cbff5edff7258081fd73f98a1cb2857cb9824 192.168.198.128:6381
  slots: (0 slots) slave
  replicates 14cc31f74c23fa6b237334b11d984989c6d8cc4e
M: f4c656b100cc40650cbcbb266cb5523020fb4b38 192.168.198.130:5379
  slots:0-5460 (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)? 500 #根据提示选择要迁移的slot数量(ps:这里选择500
What is the receiving node ID? 0ab74446f7052b1c681a2cce11f46298c5fa93bb #选择要接受这些slot的node-id
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.
 #选择slot来源:  
#all表示从所有的master重新分配,表示全部节点重新洗牌  
#done表示输入某个主节点的node id,然后再输入done,就好比从某个节点抽牌。
Source node #1:all
 
Ready to move 500 slots.
 Source nodes:
M: 8e2ad457f09186549b714c2260742773de1db658 192.168.198.130:5381
  slots:5461-10922 (5462 slots) master
  1 additional replica(s)
M: 14cc31f74c23fa6b237334b11d984989c6d8cc4e 192.168.198.130:5380
  slots:10923-16383 (5461 slots) master
  1 additional replica(s)
M: f4c656b100cc40650cbcbb266cb5523020fb4b38 192.168.198.130:5379
  slots:0-5460 (5461 slots) master
  1 additional replica(s)
 Destination node:
M: 0ab74446f7052b1c681a2cce11f46298c5fa93bb 192.168.198.128:6382
  slots: (0 slots) master
  0 additional replica(s)
 Resharding plan:
Moving slot 5461 from 8e2ad457f09186549b714c2260742773de1db658
Moving slot 5462 from 8e2ad457f09186549b714c2260742773de1db658
Moving slot 5463 from 8e2ad457f09186549b714c2260742773de1db658
Moving slot 5464 from 8e2ad457f09186549b714c2260742773de1db658
Moving slot 5465 from 8e2ad457f09186549b714c2260742773de1db658
Moving slot 5466 from 8e2ad457f09186549b714c2260742773de1db658
 
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot 5461 from 192.168.198.130:5381 to 192.168.198.128:6382: 
 
再次检查该节点
[root@localhost redis]# redis-trib.rb check 192.168.198.128:6382
>>> Performing Cluster Check (using node 192.168.198.128:6382)
M: 0ab74446f7052b1c681a2cce11f46298c5fa93bb 192.168.198.128:6382
  slots:0-165,5461-5627,10923-11088 (499 slots) master #此时已经有slot了
  0 additional replica(s)
 
 
2、添加slave节点
 
新增从节点有两种方法,第一个是使用上面的redis-trib脚本,增–slave选项,类似这样:
 
redis-trib.rb add-node --slave 192.168.198.128:6383 192.168.198.128:6382
 
注意到上面的命令行跟我们加主节点的命令行类似,所以没有没有指定新增的从节点的主节点是哪个,这时候redis-trib会在
拥有最少从节点的主节点中随机选一个作为新增节点的主节点。
 
当然也可以通过如下的命令指定新增从节点的主节点:
redis-trib.rb add-node --slave --master-id 0ab74446f7052b1c681a2cce11f46298c5fa93bb 192.168.198.128:6383 192.168.198.128:6382
用上面的指令,我们可以指定新的从节点是那个主节点的副本集。
 
>>> Adding node 192.168.198.128:6383 to cluster 192.168.198.128:6382
>>> Performing Cluster Check (using node 192.168.198.128:6382)
M: 0ab74446f7052b1c681a2cce11f46298c5fa93bb 192.168.198.128:6382
  slots:0-165,5461-5627,10923-11088 (499 slots) master
  0 additional replica(s)
S: 399cbff5edff7258081fd73f98a1cb2857cb9824 192.168.198.128:6381
  slots: (0 slots) slave
  replicates 14cc31f74c23fa6b237334b11d984989c6d8cc4e
S: e97d65ce427e00b4ff89014dcdb05cfdad9f8152 192.168.198.128:6380
  slots: (0 slots) slave
  replicates f4c656b100cc40650cbcbb266cb5523020fb4b38
M: f4c656b100cc40650cbcbb266cb5523020fb4b38 192.168.198.130:5379
  slots:166-5460 (5295 slots) master
  1 additional replica(s)
M: 14cc31f74c23fa6b237334b11d984989c6d8cc4e 192.168.198.130:5380
  slots:11089-16383 (5295 slots) master
  1 additional replica(s)
M: 8e2ad457f09186549b714c2260742773de1db658 192.168.198.130:5381
  slots:5628-10922 (5295 slots) master
  1 additional replica(s)
S: 659b9e99cfe7cfe198d10231bc4526a34c316cdc 192.168.198.128:6379
  slots: (0 slots) slave
  replicates 8e2ad457f09186549b714c2260742773de1db658
[OK] All nodes agree about slots configuration.
 
 
 
3、故障测试
 
192.168.198.128:6382> SHUTDOWN (责任编辑:liangzh)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
栏目列表
推荐内容