redis集群管理_万金油_新浪博客

1.管理集群
2.添加新节点
3.添加从节点
练习添加主机
练习删除主机

环境准备:
1.准备两台新主机,开启redis服务(开启集群功能)
2.修改启动脚本

58主机
[root@host58 ~]# redis-cli  -h 192.168.4.57 -p 6357
192.168.4.57:6357> keys *
(empty list or set)
192.168.4.57:6357> cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:0
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0
192.168.4.57:6357> cluster nodes
19b1545610997954ec6370bafac834a54efc02d7 :6357@16357 myself,master - 0 0 0 connected

检查(51~56)是否能通信:
[root@host58 ~]# ping -c2 192.168.4.52


[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351   //检查集群信息

添加master新的主机:
新主机做集群配置,并运行 redis 服务
1.添加从节点
# ./redis-trib.rb add-node --slave --master-id id 值
#从节点 ip: 端口 192.168.4.51:6351

[root@host51 src]# ./redis-trib.rb add-node 192.168.4.57:6357 192.168.4.51:6351
>>> Adding node 192.168.4.57:6357 to cluster 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   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.
>>> Send CLUSTER MEET to node 192.168.4.57:6357 to make it join the cluster.
[OK] New node added correctly.

2.查看集群信息:
[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351      
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots: (0 slots) master
   0 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   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.


3.对集群进行重新分片(0~16383)

[root@host51 src]# ./redis-trib.rb reshard  192.168.4.51:6351
[root@host51 src]# ./redis-trib.rb add-node 192.168.4.57:6357 192.168.4.51:6351
>>> Adding node 192.168.4.57:6357 to cluster 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   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.
>>> Send CLUSTER MEET to node 192.168.4.57:6357 to make it join the cluster.
[OK] New node added correctly.
[root@host51 src]# 
[root@host51 src]# ./redis-trib.rb reshard  192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots: (0 slots) master
   0 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   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)? 4096
What is the receiving node ID? 19b1545610997954ec6370bafac834a54efc02d7
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

Ready to move 4096 slots.
  Source nodes:
    M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
    M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
    M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
  Destination node:
    M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots: (0 slots) master
   0 additional replica(s)
  Resharding plan:

查看集群信息:
[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 ( 4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 ( 4096 slots) master
   0 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:6827-10922 ( 4096 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 ( 4096 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.


添加从节点(slave 的主机)
对添加为从节点的主机做如下配置
– 装包 修改配置文件 启动 redis 服务
• 添加从节点
# ./redis-trib.rb add-node --slave --master-id id 值
从节点 ip: 端口 192.168.4.51:6351

[root@host58 ~]# ss -ntulp | grep redis
tcp    LISTEN     0      128    192.168.4.58:6358                  *:*                   users:(("redis-server",pid=5313,fd=6))
tcp    LISTEN     0      128    192.168.4.58:16358                 *:*                   users:(("redis-server",pid=5313,fd=8))

[root@host58 ~]# redis-cli  -h 192.168.4.58 -p 6358
192.168.4.58:6358> cluster nodes
af602cf973932cd3cb8d3b9cb3d3fa557a3b10cc :6358@16358 myself,master - 0 0 0 connected
192.168.4.58:6358> cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:0
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0

[root@host51 src]# ./redis-trib.rb  add-node   --slave 192.168.4.58:6358  192.168.4.51:6351
>>> Adding node 192.168.4.58:6358 to cluster 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 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.
Automatically selected master 192.168.4.57:6357
>>> Send CLUSTER MEET to node 192.168.4.58:6358 to make it join the cluster.
Waiting for the cluster to join.
>>> Configure node as replica of 192.168.4.57:6357.
[OK] New node added correctly.

192.168.4.58:6358> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:4
cluster_current_epoch:9
cluster_my_epoch:9
cluster_stats_messages_ping_sent:86
cluster_stats_messages_pong_sent:86
cluster_stats_messages_meet_sent:6
cluster_stats_messages_sent:178
cluster_stats_messages_ping_received:84
cluster_stats_messages_pong_received:92
cluster_stats_messages_meet_received:2
cluster_stats_messages_received:178

[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
    1 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: af602cf973932cd3cb8d3b9cb3d3fa557a3b10cc 192.168.4.58:6358
   slots: (0 slots) slave
   replicates 19b1545610997954ec6370bafac834a54efc02d7
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 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.

客户端访问:新的主机
[root@host50 ~]# redis-cli -c -h 192.168.4.57 -p 6357
192.168.4.57:6357> keys *
1) "name"
2) "nme"
3) "age"
192.168.4.57:6357> set x 999
-> Redirected to slot [16287] located at 192.168.4.54:6354
OK


给slave主机是指定master

给50主机配置,redis服务,开启集群功能:
[root@host50 ~]# yum -y install  gcc gcc-c++
[root@host50 ~]# ss -ntulp | grep redis
tcp    LISTEN     0      128    192.168.4.50:6350                  *:*                   users:(("redis-server",pid=7350,fd=6))
tcp    LISTEN     0      128    192.168.4.50:16350                 *:*                   users:(("redis-server",pid=7350,fd=8))

[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
S: 29023faf64c53fedbe7d8861ec548d3b12c9e821 192.168.4.53:6353
   slots: (0 slots) slave
   replicates cd3542ec299850a4a8f2c8cf42874ac06d3f19b6
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: af602cf973932cd3cb8d3b9cb3d3fa557a3b10cc 192.168.4.58:6358
   slots: (0 slots) slave
   replicates 19b1545610997954ec6370bafac834a54efc02d7
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 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.

 
删除slave主机53
• 从节点主机没有槽位范围,直接执行移除命令即可
– redis-trib.rb del-node 192.168.4.51:6351 被移除
主机的 ID

]#redis-trib.rb del-node 192.168.4.51:6351 9c507832f99b9af535
63646a06c5b0525e8fcb4a

[root@host51 src]# ./redis-trib.rb  del-node 192.168.4.51:6351 29023faf64c53fedbe7d8861ec548d3b12c9e821
>>> Removing node 29023faf64c53fedbe7d8861ec548d3b12c9e821 from cluster 192.168.4.51:6351
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   1 additional replica(s)
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: af602cf973932cd3cb8d3b9cb3d3fa557a3b10cc 192.168.4.58:6358
   slots: (0 slots) slave
   replicates 19b1545610997954ec6370bafac834a54efc02d7
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

删除master主机 57
[root@host51 src]# ./redis-trib.rb  del-node 192.168.4.51:6351   19b1545610997954ec6370bafac834a54efc02d7
>>> Removing node 19b1545610997954ec6370bafac834a54efc02d7 from cluster 192.168.4.51:6351
[ERR] Node 192.168.4.57:6357 is not empty! Reshard data away and try again.
因为hasha槽还在占用
 
1.释放hasha槽

[root@host51 src]# ./redis-trib.rb  reshard 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 slots) master
   0 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)? 4096
What is the receiving node ID? c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4  //给的主机
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:19b1545610997954ec6370bafac834a54efc02d7   //拿出来的主机
Source node #2:done

Ready to move 4096 slots.
  Source nodes:
    M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots:0-1364,5461-6826,10923-12287 (4096 slots) master
   0 additional replica(s)
  Destination node:
    M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:6827-10922 (4096 slots) master
   1 additional replica(s)


[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
    slots: (0 slots) master
   0 additional replica(s)
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:0-1364,5461-12287 (8192 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

删除主机:
[root@host51 src]# ./redis-trib.rb del-node 192.168.4.51:6351 19b1545610997954ec6370bafac834a54efc02d7
>>> Removing node 19b1545610997954ec6370bafac834a54efc02d7 from cluster 192.168.4.51:6351
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.

再次查看集群信息:
[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:0-1364,5461-12287 (8192 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.


把修复好的master主机添回到集群中:
踢出集群的主机,自动关闭redis服务,需要把redis的服务从新开启,并查看集群信息和节点信息

[root@host57 ~]# ss -ntulp | grep redis
[root@host57 ~]# /etc/init.d/redis_6379  start
Starting Redis server...
[root@host57 ~]# ss -ntulp | grep redis
tcp    LISTEN     0      128    192.168.4.57:6357                  *:*                   users:(("redis-server",pid=9441,fd=6))
tcp    LISTEN     0      128    192.168.4.57:16357                 *:*                   users:(("redis-server",pid=9441,fd=8))
[root@host57 ~]# redis-cli -h 192.168.4.57 -p 6357
192.168.4.57:6357> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:10
cluster_my_epoch:9
cluster_stats_messages_ping_sent:89
cluster_stats_messages_sent:89
cluster_stats_messages_pong_received:89
cluster_stats_messages_received:89
192.168.4.57:6357> 
192.168.4.57:6357> cluster nodes
cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354@16354 master - 0 1532939768184 8 connected 12288-16383
c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352@16352 master - 0 1532939766000 10 connected 0-1364 5461-12287
bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355@16355 slave 07df1de074025884c615cc2b0e1331742ca77419 0 1532939767000 1 connected
07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351@16351 master - 0 1532939768000 1 connected 1365-5460
a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356@16356 slave c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 0 1532939767179 10 connected
19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357@16357 myself,master - 0 1532939459251 9 connected

[root@host58 ~]# ss -ntulp | grep redis
[root@host58 ~]# /etc/init.d/redis_6379  start
Starting Redis server...
[root@host58 ~]# ss -ntulp | grep redis
tcp    LISTEN     0      128    192.168.4.58:6358                  *:*                   users:(("redis-server",pid=9175,fd=6))
tcp    LISTEN     0      128    192.168.4.58:16358                 *:*                   users:(("redis-server",pid=9175,fd=8))
[root@host58 ~]# redis-cli  -h 192.168.4.58 -p 6358
192.168.4.58:6358> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:7
cluster_size:3
cluster_current_epoch:10
cluster_my_epoch:10
cluster_stats_messages_ping_sent:60
cluster_stats_messages_sent:60
cluster_stats_messages_pong_received:60
cluster_stats_messages_received:60
192.168.4.58:6358> 
192.168.4.58:6358> cluster nodes  //查看节点信息
af602cf973932cd3cb8d3b9cb3d3fa557a3b10cc 192.168.4.58:6358@16358 myself,slave c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 0 1532939659026 0 connected
c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352@16352 master - 0 1532939740723 10 connected 0-1364 5461-12287
bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355@16355 slave 07df1de074025884c615cc2b0e1331742ca77419 0 1532939739218 1 connected
19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357@16357 master - 0 1532939739218 9 connected
07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351@16351 master - 0 1532939740000 1 connected 1365-5460
a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356@16356 slave c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 0 1532939740000 10 connected
cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354@16354 master - 0 1532939740222 8 connected 12288-16383

3.1 把修复的master的redis 服务器再次添加到集群中

[root@host51 src]# ./redis-trib.rb add-node 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.51:6351
>>> Adding node 19b1545610997954ec6370bafac834a54efc02d7 to cluster 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:0-1364,5461-12287 (8192 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Invalid IP or Port (given as 19b1545610997954ec6370bafac834a54efc02d7) - use IP:Port format
##报错信息,无效的ip和端口

192.168.4.57:6357> cluster  reset
OK
192.168.4.57:6357> cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:0
cluster_current_epoch:10
cluster_my_epoch:9
cluster_stats_messages_ping_sent:1430
cluster_stats_messages_pong_sent:230
cluster_stats_messages_sent:1660
cluster_stats_messages_ping_received:230
cluster_stats_messages_pong_received:1430
cluster_stats_messages_received:1660
192.168.4.57:6357> cluster nodes
19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357@16357 myself,master - 0 1532939459251 9 connected
192.168.4.57:6357> keys *
(empty list or set)

把修复好的主机,添回集群
[root@host51 src]# ./redis-trib.rb add-node 192.168.4.57:6357  192.168.4.51:6351
>>> Adding node 192.168.4.57:6357 to cluster 192.168.4.51:6351
>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:0-1364,5461-12287 (8192 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
[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.4.57:6357 to make it join the cluster.
[OK] New node added correctly.


[root@host51 src]# ./redis-trib.rb check 192.168.4.51:6351>>> Performing Cluster Check (using node 192.168.4.51:6351)
M: 07df1de074025884c615cc2b0e1331742ca77419 192.168.4.51:6351
   slots:1365-5460 (4096 slots) master
   1 additional replica(s)
M: 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.57:6357
   slots: (0 slots) master
   0 additional replica(s)
S: bdee4e018b155fb55d25be5956bcef0de69c73d1 192.168.4.55:6355
   slots: (0 slots) slave
   replicates 07df1de074025884c615cc2b0e1331742ca77419
M: c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4 192.168.4.52:6352
   slots:0-1364,5461-12287 (8192 slots) master
   1 additional replica(s)
S: a9cc8b066e53b38391172a200b48f96b1cde40fc 192.168.4.56:6356
   slots: (0 slots) slave
   replicates c4ff83ca9d9b2d91e74806a0f6b9fc2060ccd4f4
M: cd3542ec299850a4a8f2c8cf42874ac06d3f19b6 192.168.4.54:6354
   slots:12288-16383 (4096 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

重新分配hasha槽
[root@host51 src]# ./redis-trib.rb  reshard 192.168.4.51:6351

把修复好的slave从库从新添加到集群中
[root@host58 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@host58 ~]# redis-cli  -h 192.168.4.58 -p 6358
192.168.4.58:6358> cluster reset
OK


[root@host51 src]# ./redis-trib.rb  add-node --slave --master-id 19b1545610997954ec6370bafac834a54efc02d7 192.168.4.58:6358 192.168.4.51:6351

查看主机信息:
192.168.4.58:6358> INFO  replication
# Replication
role:slave
master_host:192.168.4.57
master_port:6357
master_link_status:up
master_last_io_seconds_ago:3
master_sync_in_progress:0
slave_repl_offset:1428
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:068ad72ce1a3c819371e47d565bb438d83d99f19
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:1428
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:1428















评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

运维螺丝钉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值