Redis node Configuration

Source: Internet
Author: User
Tags hash redis redis cluster

Description

After the Redis cluster is built, for subsequent operations and in-use processes need to add, delete, modify, and so on to the service node nodes in the incoming cluster, the following records the processing of node in the specific environment:

1 node Configuration management 1.1 Parameter Description

The operation to create the cluster can be done by using the redis-trib.rb located within the Redis installation folder, REDIS-TRIB.RB is a Redis cluster manager developed using Ruby, has the ability to create clusters, check the cluster's on-line status and slot assignment, The functions of re-sharding the cluster, adding new nodes to the cluster, or removing nodes from the cluster;

REDIS-TRIB.RB Parameters:

[root@node01src]$ ./REDIS-TRIB.RB

Usage:redis-trib <command> <options> <arguments ...>

Create Host1:port1 ... Hostn:portn

--replicas <arg>

Check Host:port

Fix Host:port

Reshard Host:port

--from <arg>

--to <arg>

--slots <arg>

--yes

Add-node New_host:new_portexisting_host:existing_port

--slave

--master-id <arg>

Del-node Host:port node_id

Set-timeout Host:port milliseconds

Call Host:port command arg arg. Arg

Import Host:port

--from <arg>

Help (show this help)

1.2 primary Node increase

./redis-trib.rb add-node 127.0.0.1:7006127.0.0.1:7000

can see. Use the addnode command to add a node, the first parameter is the address of the new node, and the second parameter is the IP and port of any node that already exists .

We can see that the new node has been added to the cluster:

The new node is now connected to the cluster, becoming a part of the cluster, and can turn to the client's command request, but the new node has a two-point difference compared to the other master nodes:

· The new node does not contain any data because it does not contain any hash slots.

· Although the new node does not contain any hash slots, it is still a master node, so the new node will not be selected when the cluster needs to upgrade a slave node to a new master node.

Next, as long as you use the Redis-trib program to move some of the hash buckets in the cluster to the new node, the new node becomes the true master node.

1.3 Increase from node

There are two ways to add a slave node, you can use the Redis-trib command as you would add a master node, or you can use the--slave option as in the following example:

./redis-trib.rb Add-node--slave 127.0.0.1:7006127.0.0.1:7000

The command here is similar to adding a Master node command, where the primary node of the slave node is not specified, and in this case the system randomly selects one of the primary nodes in the other replication set as the slave node.

You can specify the master node with the following command:

./redis-trib.rb add-node--slave--master-id3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 127.0.0.1:7006 127.0.0.1:7000

You can also use the Clusterreplicate command to add a. This command can also change the master node from the node.

For example, to add a 127.0.0.1:7005 from a node to the primary node, the hash slot of the node is in the range 1423-16383, the node ID 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e, We need to link the new node (already an empty master node) and execute the command:

Redis 127.0.0.1:7006> Cluster replicate3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e

Our new slave nodes have some hash slots, other nodes know (their own configuration will be updated in a few seconds) and can be confirmed using the following command:

$ redis-cli-p 7000 cluster Nodes | grep slave | grep3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e

./redis-cli-h 172.168.63.202-p 7000 cluster nodes |grep slave | grep e0d02d64b9c14db140daef9b4d2489bbde25fe42

f093c80dde814da99c5cf72a7dd01590792b783b 127.0.0.1:7006slave 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 0 1385543617702 3 Connected

2938205e12de373867bf38f1ca29d31d0ddb3e46 127.0.0.1:7002slave 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 0 1385543617198 3 Connected

Node 3c3a0c ... There are two from nodes, 7002 (already present) and 7006 (newly added).

1.4 Node Removal

As long as you use the Redis-tribdel-node command:

./redis-trib del-node 127.0.0.1:7000 ' <node-id> '

The first parameter is the address of any one node, and the second node is the address of the node that you want to remove.

Use the same method to remove the master node, but before removing the master node, you need to make sure that the primary node is empty . If it is not empty, you need to re-shard the node's data to the other master nodes.

The alternative to removing the master node is to perform a manual failback, and the removed master node will exist as a slave node, but in this case there will be no reduction in the number of cluster nodes and the need to re-shard the data.

1.5 Transfer from node

There will be a situation in the Redis cluster that changes a slave node's primary node, which requires the following command:

Cluster replicate <new-master-node-id>

In a specific scenario, without the assistance of a system administrator, automating the automatic reconfiguration of a node from the current master node to another main section is called a replication migration (migrating from a node), and migrating from a node can improve the availability of the entire Redis cluster.

1.6 node re-sharding

The re-sharding operation basically moves the hash slots on some nodes to the other nodes, and, like creating a cluster, re-sharding can also be performed using the Redis-trib program. Execute the following command to start a re-shard operation:

./redis-trib.rb Reshard 127.0.0.1:7000

You need to specify the address of one of the nodes in the cluster, and Redis-trib will automatically find the other nodes in the cluster.

At present Redis-trib can only be done with the assistance of the administrator to complete the re-shard work, to let Redis-trib automatically move the hash slot from one node to another node, currently do not

How many slots does want to move (from 1 to 16384)?

Input: 100

Attempting to re-shard from 100 slots, in addition to the number of hash slots moved, Redis-trib also needs to know the target of the re-sharding, that is, the node responsible for receiving the 1000 hash slots.

What is the Receivingnode ID?

Input: E0d02d64b9c14db140daef9b4d2489bbde25fe42

My target node is e0d02d64b9c14db140daef9b4d2489bbde25fe42.

Now you need to specify the node from which to move the keys to the target secondment I entered all, which would fetch some hash slots from each of the other master.

Do you want to proceedwith the proposed Reshard plan (yes/no)?

Input:Yes

After the final confirmation you will see the information of each redis-trib moving slot, and the information of each key's movement will be printed.

In the process of re-sharding, you have to sample the program is not affected, you can stop or restart multiple times.

After the re-sharding is complete, you can check the cluster status with the following command:

172.168.63.204:7001> Cluster Slots



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.