Install and configure redis cluster (2)

Source: Internet
Author: User
Tags redis cluster

Content length limit of 51. Here we will continue simple Use and Maintenance of redis cluster.


7. Let's test the cluster.

7.1 Test Data Distribution


Use redis-CLI to test cluster shard. We can see that foo-> bar is stored on node 7002 and automatically jumps to node 7002, then hello-world on 7002 is stored on 7000, and is redirected to the 7000 node again.

# The-C option is to enter cluster mode $ redis-cli-C-P 7000127.0.0.1: 7000> set Foo bar-> redirected to slot [12182] located at 127.0.0.1: 7002ok127. 0.0.1: 7002> set Hello world-> redirected to slot [866] located at 127.0.0.1: 7000ok127. 0.0.1: 7000> Get foo-> redirected to slot [12182] located at 127.0.0.1: 7002 "bar" 127.0.0.1: 7002> Get hello-> redirected to slot [866] located at 127.0.0.1: 7000 "world" 127.0.0.1: 7000>


7.2 reshard


Redistribution. Here we test the reshard 1000 slots to 7000 nodes:

$./Redis-trib.rb reshard 127.0.0.1: 7000 ...... # number of slots to be migrated how many slots do you want to move (from 1 to 16384 )? 1000 # The node that receives these 1000 slots must be set to nodeidwhat is the processing ing node ID? 123ed65d59ff22370f2f09546f450d31207789f6 # here you need to set the source nodes from which slots will be selected. Here All indicates selecting please enter all the source node IDs from all nodes. type 'all' to use all the nodes as source nodes for the hash slots. type 'done' once you entered all the source nodes IDs. source node #1: All # The following lists source nodes and destination node (7000 node) Ready To Move 1000 slots. source nodes: M: 2017127.0.0.1: 7001 slots: 5962-10922 (4961 slots) Master 1 additional replica (s) M: 2017127.0.0.1: 7002 slots: 11422-16383 (4962 slots) master 1 additional replica (s) destination node: M: ipv127.0.0.1: 7000 slots: 0-5961,ipv23-11421 (6461 slots) Master 1 additional replica (s) # The following is the reshard slot plan for redis-Trib: resharding plan: moving slot 11422 from notify moving slot 11423 from notify moving slot 11424 from f5bdda1518cd3826100a30f5953ed82a5861ed48 # If you receive redis-Trib slot reshard plan, input yesdo you want to proceed with the proposed reshard Plan (yes/no) yes # Start executing reshardingmoving slot 11422 from 127.0.0.1: 7002 to 127.0.0.1: 7000: Moving slot 11423 from 127.0.0.1: 7002 to 127.0.0.1: 7000: Moving slot 11424 from 127.0.0.1: 7002 to 127.0.0.1: 7000: # Let's verify the resharding. OK $. /redis-trib.rb check 127.0.0.1: 7000 >>> memory Ming cluster check (using node 127.0.0.1: 7000) M: Memory 127.0.0.1: 7000 slots: 0-6460,42523-11922 (7461 slots) master 1 additional replica (s)


7.3 failover Test(Consistency check is not performed here, but check whether the master-slave has been switched)


First, run the debug segfault command to stop the 7002 nodes (from the preceding running log, we can see that the node is a master node)


$ Redis-cli-P 7002 debug segfault error: Server closed the connection # The following is the log of the 7002 node === redis bug report end. make sure to include from start to end. === please report the crash opening an issue on GitHub: http://github.com/antirez/redis/issues suspect Ram error? Use redis-server -- Test-memory to verify it. segmentation fault $


Then, the cluster nodes command output shows the 7002 node fail, and its slave 7005 node is upgraded to the master node.


127.0.0.1:7000> cluster nodes35e0f6fdadbf81a00a1d6d1843698613e653867b 127.0.0.1:7003 slave 123ed65d59ff22370f2f09546f410d31207789f6 0 1410838367042 7 connected61dfb1055760d5dcf6519e35435d60dc5b207940 127.0.0.1:7004 slave 82578e8ec9747e46cbb4b8cc2484c71b9b2c91f4 0 1410838368047 5 connected82578e8ec9747e46cbb4b8cc2484c71b9b2c91f4 127.0.0.1:7001 master - 0 1410838368547 2 connected 6461-10922123ed65d59ff22370f2f09546f410d31207789f6 127.0.0.1:7000 myself,master - 0 0 7 connected 0-6460 10923-11922bfc910f924d772fe03d9fe6a19aabd73d5730d26 127.0.0.1:7005 master - 0 1410838366541 8 connected 11923-16383f5bdda1518cd3826100a30f5953ed82a5861ed48 127.0.0.1:7002 master,fail - 1410838288398 1410838286795 3 disconnected127.0.0.1:7000>


After the 7002 node is started again, the 7002 node automatically becomes the slave node of the 7005 node.


127.0.0.1:7000> cluster nodes35e0f6fdadbf81a00a1d6d1843698613e653867b 127.0.0.1:7003 slave 123ed65d59ff22370f2f09546f410d31207789f6 0 1410838468336 7 connected61dfb1055760d5dcf6519e35435d60dc5b207940 127.0.0.1:7004 slave 82578e8ec9747e46cbb4b8cc2484c71b9b2c91f4 0 1410838468336 5 connected82578e8ec9747e46cbb4b8cc2484c71b9b2c91f4 127.0.0.1:7001 master - 0 1410838468837 2 connected 6461-10922123ed65d59ff22370f2f09546f410d31207789f6 127.0.0.1:7000 myself,master - 0 0 7 connected 0-6460 10923-11922bfc910f924d772fe03d9fe6a19aabd73d5730d26 127.0.0.1:7005 master - 0 1410838467334 8 connected 11923-16383f5bdda1518cd3826100a30f5953ed82a5861ed48 127.0.0.1:7002 slave bfc910f924d772fe03d9fe6a19aabd73d5730d26 0 1410838469337 8 connected127.0.0.1:7000>


7.4 Add a node

7.4.1 Add master nodes

By default, a master node is added. Similarly, in this test, the 7006/directory is added first, and then the redis. conf configuration file is edited.


Start redis-server redis. conf on the 7006 node in the 7006 directory.


The following code uses the redis-Trib tool to add 7006 nodes to the current cluster.

$. /Redis-trib.rb add-node 127.0.0.1: 7006 127.0.0.1: 7000> adding node 127.0.0.1: 7006 to cluster 127.0.0.1: 7000...> please Ming cluster check (using node 127.0.0.1: 7000 )... connecting to node 127.0.0.1: 7006: OK // here, send the cluster meet command to the 7006 node and ask it to join the cluster >>> send cluster meet to node 127.0.0.1: 7006 to make it join the cluster. [OK] new node added correctly.


At this time, the 7006 node has been added to the cluster, and can receive commands from the client and execute redirection

7.4.2 Add a Server Load balancer Node

There are two ways to add a slave node:

1) Use the -- slave option to add a Server Load balancer node. Here, the new 7007 node is used as the Server Load balancer node of 7005 (currently the master node ).

$. /Redis-trib.rb add-node -- slave -- master-ID 2017127.0.0.1: 7007 127.0.0.1: 7000 >>>> adding node 127.0.0.1: 7007 to cluster 127.0.0.1: 7000 connecting to node 127.0.0.1: 7000: OK...> during Ming cluster check (using node 127.0.0.1: 7000) S: 2017127.0.0.1: 7003 slots: (0 slots) slave replicates failed: 2017127.0.0.1: 7005 slots: 11923-16383 (4461 slots) master 1 additional replica (s )...... [OK] All nodes agree about slots configuration. >>> check for open slots... >>> check slots coverage... [OK] All 16384 slots covered. // Add 7007 to the cluster and configure the 7005 slave node connecting to node 127.0.0.1: 7007: OK >>> send cluster meet to node 127.0.0.1: 7007 to make it join the cluster. waiting for the cluster to join. >>> configure node as replica of 127.0.0.1: 7005. [OK] new node added correctly. [[email protected] redis-cluster] #127.0.0.1: 7000> cluster route 127.0.0.1: 7007 Slave Route 0 1410844154906 8 Route 127.0.0.1: 7006 master-0 1410844155909 0 Route 127.0.0.1: 7003 slave 123ed65d59ff22370f2f09546fda-d31207789f6 0 1410844154405 7 109127.0.0.1: 7004 slave limit 0 1410844153905 5 connected82578e8ec9747e46cbb4b8cc2484c71b9b2c91f4 127.0.0.1: 7001 master-0 1410844153905 2 connected limit 127.0.0.1: 7000 myself, master-0 0 7 connected 0-6460 running 127.0.0.1: 7005 master-0 1410844155408 8 connected running 127.0.0.1: 7002 slave running 0 1410844154406 8 connected127.0.0.1: 7000>


2) PassCluster replicateCommand to add the slave node, as follows:

# Add the 7007 node as the nodeid = bfc910f924d772fe03d9fe6a19aabd73d5730d26 slave node 127.0.0.1: 7007> cluster replicate slave

---------

7.4 delete a node

7.4.1 delete an slave Node

You can use the Del-node command of redis-Trib to delete an slave node, for example:
 

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


Node-ID is the nodeid of the slave node to be deleted.

7.4.2 delete a master node

You can also use the Del-node command to delete the master node, but it must be empty. Therefore, you need to migrate data to other master nodes through reshard before deleting the master node.
Of course, you can also use the above cluster failover command to delete the master node and select a slave as the new master node.

This article is from the "quiet Madman" blog, please be sure to keep this source http://quietmadman.blog.51cto.com/3269500/1553238

Install and configure redis cluster (2)

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.