Redis Dynamic Add Removal node

Source: Internet
Author: User
Tags redis redis cluster

Redis Cluster Add node

1: Start the node that needs to be added first

cd/usr/local/cluster/

mkdir 7006

cp/usr/local/cluster/redis.conf/usr/local/cluster/7006/

cd/usr/local/cluster/7006/

VI redis.conf

# The value of the port parameter in #修改redis. conf is 7006

Redis-server redis.conf

2: Add the new node to the cluster by executing the following command


cd/usr/local/redis3.0/src/

./redis-trib.rb Add-node 127.0.0.1:7006 127.0.0.1:7000

Note that this place adds a node with two nodes, a new node in front, and a node that is already in the back.

New_host:new_port Existing_host:existing_port

3: Execute command redis-cli-c-P 7000 cluster nodes, see just the new node

4: After adding a new node, the new node can be either the primary node or the node

4.1 This node into the main node, using the Redis-trib program, the cluster of some of the hash slot into the new node, the new node becomes the real master node.

Perform the following command to move the hash slot in the cluster

Cd/usr/local/redis3.0/src

./redis-trib.rb Reshard 127.0.0.1:7000

The system will prompt us how many hash slots to move, here move 1000

Then you need to specify which node to transfer the hash slots to,

Enter the ID of the node we just added

f32dc088c881a6b930474fc5b52832ba2ff71899

And then we need to specify which points to transfer, the hash slots.

Enter all to randomly transfer from all of the master nodes, enough to gather 1000 hash slots

Then enter the Yes,redis cluster and start allocating the hash slot.

At this point, a new master node is added, executing commands to view the status of nodes in the current cluster

REDIS-CLI-C-P 7000 cluster nodes

4.2: Turn this node into a node from

We've already added this new node to the cluster, and now we want to make the new Node a 127.0.0.1:7001 node, just execute the command below, and the node ID behind the command is the 127.0.0.1:7001 node ID.

REDIS-CLI-C-P 7006 cluster replicate 0B00721A509444DB793D28448D8F02168B94BD38

Use the following command to confirm whether 127.0.0.1:7006 has become a 127.0.0.1:7001 from node

REDIS-CLI-P 7000 Cluster Nodes | grep slave | grep 0b00721a509444db793d28448d8f02168b94bd38

See the picture below to indicate that the addition was successful

Redis Cluster Delete node

1: If the deleted node is the master node, here we delete the 127.0.0.1:7006 node, which has 1000 hash slots

First, you move the hash slot in the node to another node, and execute the following command

Cd/usr/local/redis3.0/src

./redis-trib.rb Reshard 127.0.0.1:7000

The system prompts us how many hash slots to move, moving 1000 here because the 127.0.0.1:7006 node has 1000 hash slots

The system then prompts us to enter the ID of the node to receive these hash slots, using the 127.0.0.1:7001 node ID

Then we have to choose from those nodes to transfer the hash slot, here must be entered 127.0.0.1:7006 this node ID, the last input done means input complete

In the final step, use the following command to delete this node

cd/usr/local/redis3.0/src/

./redis-trib.rb Del-node 127.0.0.1:7006 127.0.0.1:7006

2: If the node is from the node, directly use the following command to delete.

cd/usr/local/redis3.0/src/

./redis-trib.rb Del-node 127.0.0.1:7006 127.0.0.1:7006

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.