Redis Cluster Management Redis cluster cluster nodes increase or decrease

Source: Internet
Author: User
Tags redis cluster

The previous article explains the process of building the Redis cluster based on Redis cluster, and continues to explain the increase and decrease of node in the Redis cluster below. adding nodes in a cluster

Let's test again, add a new node, in 2 cases, 1 as the primary node, 2 as a node from the node. Let's try this separately: Create a new 7006 node to join as a primary node:
New 7006 directory, copy configuration file, modify port, start 7006 Port Redis;

[Root@spg 7006]# Ps-ef | grep redis
root      3063  2974  0 20:04 pts/0 00:00:12 redis-server    *:7001 [cluster]
root      3081  2974  0 20:05 pts/0    00:00:11 redis-server *:7002 [cluster]
root      3093  2974  0 20:05 pts/0    00:00:11 redis-server *:7003 [cluster]
root      3109  2974  0 20:06 pts/0    00:00:11 Redis-server *:7004 [cluster]
root      3123  2974  0 20:06 pts/0    00:00:11 redis-server *:7005 [ Cluster]
root      3487  2974  0 20:30 pts/0 00:00:06 redis-server    *:7000 [cluster]
root      3981  2974  0 21:09 pts/0    00:00:00 redis-server *:7006 [cluster]
root      3993  2974  0 21:09 pts/0    00:00:00 grep--color=auto Redis

To join 7006 nodes in the cluster:

REDIS-TRIB.RB Add-node 127.0.0.1:7006 127.0.0.1:7000

Add-node is a join instruction, 127.0.0.1:7006 represents the newly added node, 127.0.0.1:7000 represents a node of the cluster that is joined to identify which cluster, theoretically, which is possible.

[Root@spg 7006]# redis-trib.rb add-node 127.0.0.1:7006 127.0.0.1:7000 >>> Adding node 127.0.0.1:7006 to cluster 1 27.0.0.1:7000 Connecting to node 127.0.0.1:7000:ok connecting to node 127.0.0.1:7003:ok connecting to Node 127.0.0.1:700 2:ok Connecting to node 127.0.0.1:7004:ok connecting to node 127.0.0.1:7001:ok connecting to Node 127.0.0.1:7005:ok T;>> performing Cluster Check (using node 127.0.0.1:7000) s:be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000 Slots: (0 slots) slave replicates 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c m:1da8a7f4c3cd5d7537e90e0 ca5f4fb416f41a40c 127.0.0.1:7003 slots:0-5460 (5461 Slots) Master 1 additional replica (s) m:947cc4a9e890672cfad4806 A5921E9F8BDF05C05 127.0.0.1:7002 slots:10923-16383 (5461 Slots) Master 1 additional replica (s) s:05ac96f9cdee679f98 E8f7ce8e97cf1cbea608ca 127.0.0.1:7004 Slots: (0 slots) Slave replicates ce06b13387702c3ee63e0118dd10c5f81a1285b5 M: ce06b13387702c3ee63e0118dd10c5f81a1285B5 127.0.0.1:7001 slots:5461-10922 (5462 Slots) Master 1 additional replica (s) s:b65f33d97416795226964aa22f3b4a8ac7 366a99 127.0.0.1:7005 Slots: (0 slots) slave replicates 947cc4a9e890672cfad4806a5921e9f8bdf05c05 [OK] all nodes Agre
e about slots configuration.
>>> Check for open slots ... >>> check slots coverage ... [OK]
All 16384 slots covered.
Connecting to Node 127.0.0.1:7006:ok >>> Send CLUSTER MEET to node 127.0.0.1:7006 to make it join the CLUSTER. [OK] New node added correctly.

You can see from above that node 7006 has successfully joined the cluster, where you can view the cluster node status

[Root@spg 7006]# redis-trib.rb check 127.0.0.1:7000 connecting to node 127.0.0.1:7000:ok connecting to Node 127.0.0.1:700 6:ok Connecting to node 127.0.0.1:7003:ok connecting to node 127.0.0.1:7002:ok connecting to Node 127.0.0.1:7004:ok Co Nnecting to node 127.0.0.1:7001:ok connecting to Node 127.0.0.1:7005:ok >>> performing Cluster Check (using nod e 127.0.0.1:7000) s:be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000 Slots: (0 slots) Slave replicates 7f4c3cd5d7537e90e0ca5f4fb416f41a40c m:fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006 Slots: (0 slots) Master 0 additional replica (s) m:1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003 slots:0-5460 (5461 slots) Master 1 additional replica (s) m:947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002 slots:10923-16383 (5461 SL OTS) Master 1 additional replica (s) s:05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004 slots: (0 slots) Slav E replicates ce06b13387702c3Ee63e0118dd10c5f81a1285b5 m:ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001 slots:5461-10922 (5462 slots)
   Master 1 additional replica (s) s:b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005 slots: (0 slots) Slave
Replicates 947CC4A9E890672CFAD4806A5921E9F8BDF05C05 [OK] All nodes agree about slots configuration.
>>> Check for open slots ... >>> check slots coverage ... [OK] All 16384 slots covered.

It is clear to see that node 7006 has successfully joined the cluster as the master.
PS: You can also connect to the client to view the node state in the cluster, as follows:

[Root@spg 7006]# redis-cli-c-P 7006 127.0.0.1:7006> cluster
fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006 myself,master-0 0 0 Connected
Be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000 Slave 1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 0 1456667011409 7 connected
947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002 master-0 1456667008376 3 Connected 10923-16383
ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001 master-0 1456667007371 2 connected 5461-10922
b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005 Slave 947CC4A9E890672CFAD4806A5921E9F8BDF05C05 0 1456667013968 3 connected
05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004 slave ce06b13387702c3ee63e0118dd10c5f81a1285b5 0 1456667013457 2 connected
1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003 master-0 1456667012429 7 connected 0-5460

However, through the above found:

m:fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006
   Slots: (0 slots) Master
   0 additional replica (s)

0 slots. That is, although it is now the master node, it does not assign any nodes to it, which means it is not currently responsible for data access.
It seems that Redis cluster is not a new node in the time to help us do the migration work, we need to manually to the cluster relocation, but also this command:

REDIS-TRIB.RB Reshard 127.0.0.1:7000

This command is used to migrate the slot node, the following 127.0.0.1:7000 is to indicate which cluster, port fill [7000-7006] All can, our results are run as follows:

[Root@spg 7006]# redis-trib.rb reshard 127.0.0.1:7000 Connecting to node 127.0.0.1:7000:ok Connecting to Node 127.0.0.1:7
006:ok Connecting to node 127.0.0.1:7003:ok connecting to node 127.0.0.1:7002:ok connecting to Node 127.0.0.1:7004:ok Connecting to node 127.0.0.1:7001:ok connecting to Node 127.0.0.1:7005:ok >>> performing Cluster Check (using n Ode 127.0.0.1:7000) S:be26c521481afcd6e739e2bfef69e9dcfb63d0a6 127.0.0.1:7000 Slots: (0 slots) Slave replicates 1da 8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c m:fe595e7a38c659a6eb6949bb31fd7474881d6422 127.0.0.1:7006 Slots: (0 slots) Master 0 additional replica (s) m:1da8a7f4c3cd5d7537e90e0ca5f4fb416f41a40c 127.0.0.1:7003 slots:0-5460 (5461 slots) Master 1 additional replica (s) m:947cc4a9e890672cfad4806a5921e9f8bdf05c05 127.0.0.1:7002 slots:10923-16383 (5461 SL OTS) Master 1 additional replica (s) s:05ac96f9cdee679f98e8f7ce8e97cf1cbea608ca 127.0.0.1:7004 slots: (0 slots) Slav E replicates ce06b13387702C3ee63e0118dd10c5f81a1285b5 m:ce06b13387702c3ee63e0118dd10c5f81a1285b5 127.0.0.1:7001 slots:5461-10922 (5462 slots)
   Master 1 additional replica (s) s:b65f33d97416795226964aa22f3b4a8ac7366a99 127.0.0.1:7005 slots: (0 slots) Slave
Replicates 947CC4A9E890672CFAD4806A5921E9F8BDF05C05 [OK] All nodes agree about slots configuration.
>>> Check for open slots ... >>> check slots coverage ... [OK]
All 16384 slots covered. How many slots does you want to move (from 1 to 16384)?

It prompts us to migrate how many slot to 7006, we can calculate: 16384/4 = 4096, that is to say, in order to balance the allocation, we need to move 4,096 slots to 7006.

OK, that input 4096:

How many slots does you want to move (from 1 to 16384)? 4096
What is the receiving node ID?

At this point, we are prompted to accept the Node ID, 7006 ID we can see through the above is fe595e7a38c659a6eb6949bb31fd7474881d6422

What is the receiving node ID? fe595e7a38c659a6eb6949bb31fd7474881d6422 Please enter all the
source node IDs.
  Type ' All ' to the nodes as source nodes for the hash slots.
  Type ' Done ' once your entered all source nodes IDs.
  Source node #1:

Next, Redis-trib asks you for the fragmented source node, which is the node from which to remove the 4,096 hash slots and move the slots to the 7006 node.

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.