Common operation maintenance node redis

Maintenance node

  1. Add the primary node
  2. Reassign hash slot
  3. Adding slave nodes
  4. Delete Node

 

1 Add the primary node

You can add nodes to the cluster after cluster is successfully created, the following is added a master primary node

  • Add 7007 node as a new node

Execute the command: ./ redis-trib.rb add-node 120.0.1: 7007 120.0.1: 7001

 

 

 

  • View cluster nodes found 7007 has been added to the cluster

 

 

 

 

 

 

2   Reassign hash slot

After the master node needs to be added to the master node hash slot allocation, so that the master section can store data .

  • View slot occupancy cluster

16384 Cluster redis slots, each node in the cluster distribution own groove, the groove can be seen by reviewing the occupancy cluster node.

 

 

 

 


7007 to the node just added distribution groove 

The first step : connecting the cluster (any of the available lines are connected to node cluster)

[root@A001 redis]# ./redis-trib.rb reshard 192.168.101.3:7001

 

Step Two : Enter the number of slots to be allocated

Input: 500, 500 represents slots to be allocated

 

Step node id input receiving slot:

 

Input: 15b809eadae88955e36bcdbb8144f61bbbaf38fb

PS: distribution groove here ready to 7007, 7007 to see node id as by cluster nodes:

15b809eadae88955e36bcdbb8144f61bbbaf38fb

 

Step Four : input source node id

 

Input: all

 

Step Five : Enter yes starts to move to the destination node id groove

 

Input: yes

 

 

3   Adding slave nodes

You can add nodes to the cluster after cluster is successfully created, the following is added from a slave node.

  • Add 7008 from node from the node 7007 to 7008 as

命令:./redis-trib.rb add-node --slave --master-id 主节点id 新节点的ip和端口 旧节点ip和端口

 

执行如下命令:

./redis-trib.rb add-node --slave --master-id cad9f7413ec6842c971dbcc2c48b4ca959eb5db4  192.168.101.3:7008 192.168.101.3:7001

 

cad9f7413ec6842c971dbcc2c48b4ca959eb5db4  是7007结点的id,可通过cluster nodes查看。

 

 

 

 

注意:如果原来该结点在集群中的配置信息已经生成到cluster-config-file指定的配置文件中(如果cluster-config-file没有指定则默认为nodes.conf),这时可能会报错:

[ERR] Node XXXXXX is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0

解决方法是删除生成的配置文件nodes.conf,删除后再执行./redis-trib.rb add-node指令

 

  • 查看集群中的结点,刚添加的7008为7007的从节点:

 

 

 

 

4   删除结点

命令:./redis-trib.rb del-node 120.0.1:7005 4b45eb75c8b428fbd77ab979b85080146a9bc017

 

删除已经占有hash槽的结点会失败,报错如下:

[ERR] Node 120.0.1:7005 is not empty! Reshard data away and try again.

 

需要将该结点占用的hash槽分配出去(参考hash槽重新分配章节)。

Guess you like

Origin www.cnblogs.com/royal6/p/12131556.html