Example of adding a Delete redistribution node to Redis cluster

Source: Internet
Author: User
Tags redis cluster

When Redis cluster is configured and running for a while, we want to add nodes, or delete nodes, what to do.


One, redis cluster command line

Cluster (cluster)
CLUSTER Info Print cluster information
CLUSTER NODES Lists all nodes currently known to the cluster, as well as information about those nodes.

Nodes (node)
CLUSTER MEET <ip> <port> Add the node specified by IP and port to the cluster, making it part of the cluster.
CLUSTER Forget <node_id> removes node_id specified node from the cluster.
CLUSTER REPLICATE <node_id> Sets the current node to node_id node from the specified node.
CLUSTER Saveconfig Save the configuration file of the node to the hard disk.

Slot (slot)
CLUSTER addslots <slot> [slots ...] assigns one or more slots (slots) (assign) to the current node.
CLUSTER delslots <slot> [slots ...] removes the assignment of one or more slots to the current node.
CLUSTER Flushslots removes all slots assigned to the current node, making the current node a node without any slots assigned.
CLUSTER setslot <slot> Node <node_id> assigns the slot slot to the node specified by node_id, and if the slot is already assigned to another node, let the other node delete the slot before assigning it.
CLUSTER setslot <slot> Migrating <node_id> migrates the slot slots of this node to the nodes specified in the node_id.
CLUSTER setslot <slot> importing <node_id> import slot slots from node_id specified node to this node.
CLUSTER Setslot <slot> STABLE cancels the import or migration (migrate) of the slot slots.

Keys (key)
CLUSTER keyslot <key> Calculate the key should be placed on which slot.
CLUSTER Countkeysinslot <slot> Returns the number of key-value pairs currently contained in the slot slot.
CLUSTER Getkeysinslot <slot> <count> returns the key in count slot slots.
These commands are unique to the cluster. Execute the above command to log in first

[[email protected] redis]# redis-cli-c-P 6382-h 192.168.10.220//Login
192.168.10.220:6382> Cluster info//view cluster status
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:8
Cluster_my_epoch:4
cluster_stats_messages_sent:82753
cluster_stats_messages_received:82754


Second, add nodes


1, new configuration of two test nodes

# Cd/etc/redis

New configuration
# CP redis-6379.conf redis-6378.conf && sed-i "s/6379/6378/g" redis-6378.conf
# CP redis-6382.conf redis-6385.conf && sed-i "s/6382/6385/g" redis-6385.conf

Start
# redis-server/etc/redis/redis-6385.conf >/var/log/redis/redis-6385.log 2>&1 &
# redis-server/etc/redis/redis-6378.conf >/var/log/redis/redis-6378.log 2>&1 &


2, adding the master node


# redis-trib.rb Add-node 192.168.10.219:6378 192.168.10.219:6379 
Comment:
192.168.10.219:6378 is a new node
192.168.10.219:6379 cluster Any old node
3, add from Node
# redis-trib.rb Add-node--slave--master-id 03ccad2ba5dd1e062464bc7590400441fafb63f2 192.168.10.220:6385 192.168.10.219:6379 
Comment:
--slave, Represents the node ID of the--master-id 03ccad2ba5dd1e062464bc7590400441fafb63f2, the primary node, which is added from the nodes
, here is the node ID of the newly added 6378 in front
192.168.10.220:6385, new node
192.168.10.219:6379 any old node of the cluster


4, Reassign Slots

# redis-trib.rb Reshard 192.168.10.219:6378//The following is the main process

How many slots does want to move (from 1 to 16384)? 1000//Set slot number 1000
What is the receiving node ID? 03CCAD2BA5DD1E062464BC7590400441FAFB63F2//New Node ID
Please enter the source node IDs.
The Type ' All ' is the nodes as source nodes for the hash slots.
Type ' Done ' once your entered all the source nodes IDs.
Source node #1: All//indicates all nodes re-shuffle
Do you want to proceed with the proposed Reshard plan (yes/no)? Yes//Confirm re-score


The newly added master node, is no slots,


M:03ccad2ba5dd1e062464bc7590400441fafb63f2 192.168.10.219:6378
slots:0-332,5461-5794,10923-11255 (0 Slots) Master
If the master node is not slots, the access data will not be selected.
The process of allocation can be understood as playing poker, all means that everyone re-shuffle; Enter the node ID of a master node, and then when you enter done, it is like pulling a card from a node.


5, check the cluster situation

[Email protected] redis]# redis-trib.rb check 192.168.10.219:6379
Connecting to Node 192.168.10.219:6379:ok
Connecting to Node 192.168.10.220:6385:ok
Connecting to Node 192.168.10.219:6378:ok
Connecting to Node 192.168.10.220:6382:ok
Connecting to Node 192.168.10.220:6383:ok
Connecting to Node 192.168.10.219:6380:ok
Connecting to Node 192.168.10.219:6381:ok
Connecting to Node 192.168.10.220:6384:ok
>>> performing Cluster Check (using node 192.168.10.219:6379)
m:5d8ef5a7fbd72ac586bef04fa6de8a88c0671052 192.168.10.219:6379
slots:5795-10922 (5128 Slots) Master
1 additional replica (s)
s:9c240333476469e8e2c8e80b089c48f389827265 192.168.10.220:6385
Slots: (0 slots) Slave
Replicates 03CCAD2BA5DD1E062464BC7590400441FAFB63F2
M:03ccad2ba5dd1e062464bc7590400441fafb63f2 192.168.10.219:6378
slots:0-332,5461-5794,10923-11255 (Slots) Master
1 additional replica (s)
m:19b042c17d2918fade18a4ad2efc75aa81fd2422 192.168.10.220:6382
slots:333-5460 (5128 Slots) Master
1 additional replica (s)
M:b2c50113db7bd685e316a16b423c9b8abc3ba0b7 192.168.10.220:6383
slots:11256-16383 (5128 Slots) Master
1 additional replica (s)
S:6475E4C8B5E0C0EA27547FF7695D05E9AF0C5CCB 192.168.10.219:6380
Slots: (0 slots) Slave
Replicates 19b042c17d2918fade18a4ad2efc75aa81fd2422
S:1EE01FE95BCFB688A50825D54248EEA1E6133CDC 192.168.10.219:6381
Slots: (0 slots) Slave
Replicates b2c50113db7bd685e316a16b423c9b8abc3ba0b7
S:9a2a1d75b8eb47e05eee1198f81a9edd88db5aa1 192.168.10.220:6384
Slots: (0 slots) Slave
Replicates 5d8ef5a7fbd72ac586bef04fa6de8a88c0671052
[OK] All nodes agree about slots configuration.
>>> Check for open Slots ...
>>> Check Slots Coverage ...
[OK] All 16384 slots covered.


Third, change the master from the node

Take a look at the 6378 slave node
# redis-cli-p 6378 cluster Nodes | grep slave | grep 03ccad2ba5dd1e062464bc7590400441fafb63f2

Add 6385 to the new master
# redis-cli-c-P 6385-h 192.168.10.220
192.168.10.220:6385> cluster replicate 5d8ef5a7fbd72ac586bef04fa6de8a88c0671052//new Master's node ID
Ok
192.168.10.220:6385> quit

View the slave of the new master
# redis-cli-p 6379 cluster Nodes | grep slave | grep 5d8ef5a7fbd72ac586bef04fa6de8a88c0671052


Four, delete the node


1, remove from node

# redis-trib.rb Del-node 192.168.10.220:6385 ' 9c240333476469e8e2c8e80b089c48f389827265 '
2. Delete the master node
If the primary node has a slave node, it is transferred from the node to the other master node
If the primary node has slots, remove the allocated slots, and then delete the master node

# redis-trib.rb Reshard 192.168.10.219:6378//unassign slots, here are the main procedures

How many slots does want to move (from 1 to 16384)? 1000//Total number of slots deleted master
What is the receiving node ID? 5d8ef5a7fbd72ac586bef04fa6de8a88c0671052//Receive the Master of the 6378-node slot
Please enter the source node IDs.
The Type ' All ' is the nodes as source nodes for the hash slots.
Type ' Done ' once your entered all the source nodes IDs.
Source node #1:03ccad2ba5dd1e062464bc7590400441fafb63f2//Deleted master Node-id
Source node #2:d One

Do you want to proceed with the proposed Reshard plan (yes/no)? Yes//After canceling the slot, Reshard
After adding the master node, this step was taken, which was assigned and now removed. The opposite.

# redis-trib.rb Del-node 192.168.10.219:6378 ' 03ccad2ba5dd1e062464bc7590400441fafb63f2 '
The new master node is deleted, so it's back to the beginning of the article, and the State of the node has not been added.

Example of adding a Delete redistribution node to Redis cluster

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.