Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis Cluster-- operation and maintenance management

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In the last blog, we talked about how to install and configure Redis Cluster. For more information, please see: Redis Cluster-- installation and configuration. Today we will learn the daily operation and maintenance operations of Redis Cluster.

Cluster common commands

Cluster info cluster information cluster nodes all nodes and slot distribution cluster slots all nodes and slot distribution cluster slaves returns a slaves list of master nodes cluster meet adds the specified node to the cluster, the default is maser, which is equivalent to redis-trib.rb add-nodecluster forget deleting the specified node, which is equivalent to redis-trib.rb del-nodecluster replicate setting the current node to the slave;cluster saveconfig of the specified node-id to save the node information in nodes-6379.conf culture Cluster addslots [slot...] Assign one or more slots (slot) to the current node (assign). Cluster delslots [slot...] Removes one or more slots to the current node. Cluster flushslots removes all slots assigned to the current node, making the current node a node with no slots assigned. Cluster setslot node assigns slot slot to the node specified by node_id. Cluster setslot migrating migrates the slot slot of this node to the node specified by node_id. Cluster setslot importing imports slot slot into this node from the node specified by node_id. Cluster setslot stable cancels the import (import) or migration (migrate) of slot slot. Cluster keyslot gets the slot cluster countkeysinslot corresponding to key and returns the number of key currently contained in slot. Cluster getkeysinslot returns the keys in count slot slots.

Example:

172.16.101.54 cluster nodes4fe26b83847e8d995230b8e7e5b3ca6a5fe99c19 6379 > 172.16.101.66 connectedb50ba506525ee547823b3d9a7e5a095933e3ff42 6380 slave 58a08dff7169bb0ce289c19a6520c85131bb44da 01532789488602 9 connectedb50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 slave 4c7348ac575a1a3bd4357e937a8f94f1654193cf 01532789484595 5 connected610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.546379 myself Master-001 connected 866-546058a08dff7169bb0ce289c19a6520c85131bb44da 172.16.101.66 master-01532789489605 9 connected 0-865 5461-6826 10923-1218128e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 connected 6379 slave 610aa83831404be545b25cc7f7322e987da1dd33 01532789484095 4 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 connected 6379 master-01532789486598 2 connected 6827-10922ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 master-01532789487599 8 connected 12182-16383c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 Fringe 6379 slave ece3a80f6989fa7f8316d73ee30ceea84340f24e 01532789485597 8 connected

Create three new key and assign them to each slot according to the crc16 algorithm

172.16.101.54 located at 172.16.101.55:6379OK172.16.101.55:6379 6379 > set key1 value1- > Redirected to slot [9189] located at 172.16.101.55:6379OK172.16.101.55:6379 > set key2 value2OK172.16.101.54:6379 > set key3 value3OK

Get the value of key

172.16.101.56 get key1- > Redirected to slot [9189] located at 172.16.101.55 located at 6379 "value1" 172.16.101.55 get key2- > Redirected to slot [4998] located at 172.16.101.54 get key2- 6379 "value2" 172.16.101.566379 > get key3- > Redirected to slot [935] located at 172.16.101.54

Use the keyslot command to obtain the slot number corresponding to key according to the key name

172.16.101.54 cluster keyslot key1 6379 > cluster keyslot key3 (integer) 9189172.16.101.54 cluster keyslot key2 (integer) 4998172.16.101.54

Returns the number of corresponding key on slot slot

172.16.101.54 cluster countkeysinslot 6379 > cluster countkeysinslot 9189 (integer) 1172.16.101.54 cluster countkeysinslot 6379 > cluster countkeysinslot 4998 (integer) 1172.16.101.54

Return the count100 keys according to the slot number 9189

172.16.101.55) cluster getkeysinslot 9189 1001) "key1" 172.16.101.54 cluster getkeysinslot 4998 1001) "key2" 172.16.101.54 cluster getkeysinslot 1001) "key3"

Write key-values data test

It can be found that the data is stored in pieces on these three nodes. Although the command keys * cannot display the key of this node, we can still use the get command to get the key content and switch directly to the data node where the key is stored.

[root@sht-sgmhadoopcm-01 redis] # src/redis-cli-c-h 172.16.101.54-p 6379172.16.101.54 located at 172.16.101.56:6379OK172.16.101.56:6379 6379 > set foo bar- > Redirected to slot [12182] located at 172.16.101.56:6379OK172.16.101.56:6379 > exit [root@sht-sgmhadoopcm-01 redis] # src/redis-cli-c-h 172.16.101.54-p 6379172.16.101.54Switzerland 6379 > keys * (empty list or set) 172.16.101 .54keys 6379 > get foo- > Redirected to slot [12182] located at 172.16.101.56 located at 6379 "bar" 172.16.101.56 keys * 1) "foo" [root@sht-sgmhadoopnn-02 redis] # src/redis-cli-c-h 172.16.101.56-p 6379172.101.56 located at 6379 > set hello world- > Redirected to slot [866] located at 172.16.101.54:6379OK172.16.101.54:6379 > keys * 1) "hello"

Outage recovery test

Simulate a master failure, and the slave of the master will be upgraded to the new master. When the old master is repaired, it will be used as the slave of the new master.

[root@sht-sgmhadoopnn-02 redis] # src/redis-cli-c-h 172.16.101.56-p 6379 debug segfaultError: Server closed the connection [root@sht-sgmhadoopnn-02 redis] # ps-ef | grep redisroot 1764 1504 0 13:48 pts/2 00:00:00 grep-- color=auto redis172.16.101.54:6379 > cluster nodesb50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 cluster nodesb50ba506525ee547823b3d9a7e5a095933e3ff42 6379 slave 4c7348ac575a1a3bd4357e937a8f94f1654193cf 01532497434709 5 connected610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 myself Master-0 01 connected 0-546028e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 6379 slave 610aa83831404be545b25cc7f7322e987da1dd33 01532497438730 4 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.551579 master-0153249439732 2 connected 5461-10922ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 connected 6379 master,fail-153249356109 153249354406 3 disconnectedc79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 master-0153249437724 7 connected 10923-16383

Restart the failed node, which will serve as the slave for the new master

[root@sht-sgmhadoopnn-02 redis] # src/redis-server redis.conf [root@sht-sgmhadoopnn-02 redis] # src/redis-cli-c-h 172.16.101.56 src/redis-cli-c-h 172.16.101.56 CLUSTER NODES28e8d5c8fd12533622d8110f8d262cb50120ca02 6379 > CLUSTER NODES28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 root@sht-sgmhadoopnn-02 redis 6379 slave 610aa83831404be545b25cc7f7322e987da1dd33 01532497754924 4 connectedc79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 myself 6379 master-01532497757930 7 connected 10923-16383ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 myself Slave c79de1092011ed395ee772969274c0567c2b5dd1 0 3 connectedb50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 slave c79de1092011ed395ee772969274c0567c2b5dd1 6379 slave 4c7348ac575a1a3bd4357e937a8f94f1654193cf 01532497751918 5 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 connected 6379 master-01532497756929 2 connected 5461-10922610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.541579 master-01532497755927 1 connected 0-5460

Manual Failover

Using cluster failover on Slave to change Slave into Master, this manual failover does not lose any data, and upgrading redis is a relatively secure way.

172.16.101.56 connected 6379 > cluster nodes28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 cluster nodes28e8d5c8fd12533622d8110f8d262cb50120ca02 6379 slave 610aa83831404be545b25cc7f7322e987da1dd33 01532674427835 4 connectedc79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 master-01532674425830 7 connected 10923-16383ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.566379 Slave c79de1092011ed395ee772969274c0567c2b5dd1 0 3 connectedb50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 slave c79de1092011ed395ee772969274c0567c2b5dd1 6379 slave 4c7348ac575a1a3bd4357e937a8f94f1654193cf 01532674428837 5 connected4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 connected 6379 master-01532674429839 2 connected 5461-10922610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.543379 master-01532674426832 1 connected 0-5460172.16.101.56 slave 4c7348ac575a1a3bd4357e937a8f94f1654193cf 6379 > role1) "slave" 2) "172.16.101.60" 3) (integer) 63794) "connected" 5) (integer) 2437671716.101.56 .101.56 CLUSTER FAILOVEROK172.16.101.56:6379 > role1) "master" 2) (integer) 2468083) 1) 1) "172.16.101.60" 2) "6379" 3) "246808"

View the failover process through the log:

[root@sht-sgmhadoopnn-02 redis] # vim redis.log1766:S 27 Jul 14 Jul 54 milliseconds 56.863 # Manual failover user request accepted.1766:S 27 Jul 14 Jul 54 milliseconds 56.912 # Received replication offset for paused master manual failover: 2468071766 V 27 Jul 14 V 54 milliseconds 56.991 # All master replication stream processed, manual failover can start.1766:S 27 Jul 14 Manual failover user request accepted.1766:S 54 Start of election delayed for 0 milliseconds (rank # 0) Offset 246807) .1766 Failover election won S 27 Jul 14 Failover election won 57.091 # Starting a failover election for epoch 8.1766 V 27 Jul 54 Failover election won: I'm the new master.

Add a new Master node and assign slot

Prepare a new redis environment, keep the version consistent, use the src/redis-trib.rb add-node command to add a new node without data, otherwise an error will be reported when the node is added, and the node will automatically become a master node without any slot allocation, but we can reassign the slots through redis-trib.rb reshard/rebalance to make the data distribution more reasonable.

[root@sht-sgmhadoopcm-01 redis] # rsync-avz-- progress / usr/local/redis sht-sgmhadoopdn-04:/usr/local/ [root@sht-sgmhadoopdn-04 redis] # src/redis-server redis.conf

(1) 172.16.101.66 6379 is the address and port of the new node, and 172.16.101.54 is the IP and port of the existing node.

You can also use the cluster meet command to add nodes

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb add-node 172.16.101.66 src/redis-trib.rb add-node 6379 172.16.101.54 additional replica 6379 > Adding node 172.16.101.66 to cluster 172.16.101.54 additional replica 6379 > > Performing Cluster Check (using node 172.16.101.54) M: 610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 master 6379 slots:0-5460 (5461 slots) master 1 additional replica (s) S: b50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 Slots: (0 slots) slave replicates 4c7348ac575a1a3bd4357e937a8f94f1654193cfS: 28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 slots 6379 slots: (0 slots) slave replicates 610aa83831404be545b25cc7f7322e987da1dd33M: 4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 master 1 additional replica (s) M: ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 additional replica (s) M: ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 additional replica 6379 slots:10923-16383 (5461 slots) master 1 additional replica (s) S: c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 slots: (0 slots) slave replicates ece3a80f6989fa7f8316d73ee30ceea84340f24e [OK] All nodes agree about slots configuration. > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. > > Send CLUSTER MEET to node 172.16.101.66 All 6379 to make it join the cluster. [OK] New node added correctly.

(2) reassign slot to the new Master

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb info 172.16.101.54 slots 6379172.16.101.54 slots 6379 (610aa838...)-> 3 keys | 8086 slots | 1 slaves.172.16.101.66:6379 (58a08DFF...)-> 0 keys | 0 slots | 0 slaves.172.16.101.55:6379 (4c7348ac...)-> 1 keys | 4096 slots | 1 slaves.172.16.101.56:6379 (ece3a80f. .)-> 1 keys | 4202 slots | 1 slaves. [OK] 5 keys in 4 masters.0.00 keys per slot on average. [root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb reshard 172.16.101.54 master 6379 > Performing Cluster Check (using node 172.16.101.54 slots:0 6379) M: 610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 slots:0-6826 additional replica (s) S: b50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 6379 slots: (0 slots) slave replicates 4c7348ac575a1a3bd4357e937a8f94f1654193cfM: 58a08dff7169bb0ce289c19a6520c85131bb44da 172.16.101.66 slots 6379 slots: (0 slots) master 0 additional replica (s) S: 28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 slots 6379 slots: (0 slots) slave replicates 610aa83831404be545b25cc7f7322e987da1dd33M: 4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 master 6379 slots:6827-10922 (4096 slots) master 1 additional replica (s) M: ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 master 6379 slots:12182-16383 (4202 slots) master 1 additional replica (s) S: c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 slave replicates ece3a80f6989fa7f8316d73ee30ceea84340f24e 6379 slots: (0 slots) slave replicates ece3a80f6989fa7f8316d73ee30ceea84340f24e [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered.How many slots do you want to move (from 1 to 16384)? 866What is the receiving node ID? 58a08dff7169bb0ce289c19a6520c85131bb44daPlease enter all the source node IDs. 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.Moving slot 855 from 4c7348ac575a1a3bd4357e937a8f94f1654193cfMoving slot 856 from 4c7348ac575a1a3bd4357e937a8f94f1654193cfDo you want to proceed with the proposed reshard plan (yes/no)? yes.Moving slot 854 from 172.16.101.54 to 172.16.101.66:6379:Moving slot 6379 to 172.16.101.66:6379:Moving slot 855 from 172.16.101.54 to 172.16.101.66:6379:Moving slot 856 from 172.16.101.54:6379 to 172.16.101.66:6379:

Add a new Slave node

Specify master-id to create a Slave, the first is the IP and port of the new node, and the second is the IP and port of any existing node.

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb add-node-- slave-- master-id 3bfe06617ab8f682a6b55be38a529d9c7e1b50d0 172.16.101.66 master-id 3bfe06617ab8f682a6b55be38a529d9c7e1b50d0 172.16.101.54 master 6379 > Adding node 172.16.101.66 master 6380 to cluster 172.16.101.54 master > Performing Cluster Check (using node 172.16.101.54 master) M: 610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 master 6379 slots:0-5460 (5461 slots) master 1 additional replica (s) S: b50ba506525ee547823b3d9a7e5a095933e3ff42 172 .16.101.59: 6379 slots: (0 slots) slave replicates 4c7348ac575a1a3bd4357e937a8f94f1654193cfM: 3bfe06617ab8f682a6b55be38a529d9c7e1b50d0 172.16.101.66 slots 6379 slots: (0 slots) master 0 additional replica (s) S: 28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 slots 6379 slots: (0 slots) slave replicates 610aa83831404be545b25cc7f7322e987da1dd33M: 4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 slots:5461-10922 (5462 slots) master 1 additional replica (s) M: ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 slots:10923-16383 Slots) master 1 additional replica (s) S: c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 slots 6379 slots: (0 slots) slave replicates ece3a80f6989fa7f8316d73ee30ceea84340f24e [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered. > > Send CLUSTER MEET to node 172.16.101.66 slots 6380 to make it join the cluster.Waiting for the cluster to join. > > Configure node as replica of 172.16.101.66slots. [OK] New node added correctly.

Remove a node

If you want to delete a node, it cannot have slot. If it contains slot, it cannot be deleted, but you can remove a slave. If you want to remove a master containing slot, you need to move all the slot of that node to another master, and then delete it.

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb del-node 172.16.101.54 Node 6379 '58a08dff7169bb0ce289c19a6520c85131bb44da' > > Removing node 58a08dff7169bb0ce289c19a6520c85131bb44da from cluster 172.16.101.54 Node 6379 [ERR] Reshard data away and try again.

(1) remove a salve node

The IP and port of any existing node, and the second node is the address node-id of the node you want to remove

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb del-node 172.16.101.54 Removing node 47a9c6cd1dd9aa9edd99890d380bcaee3a807a71 from cluster 6379 '47a9c6c6cd1dd9aa9edd99890d380bcaee3a807a71' > > Removing node 47a9c6cd1dd9aa9edd99890d380bcaee3a807a71 from cluster 172.16.101.54 Sending CLUSTER FORGET messages to the cluster... > SHUTDOWN the node.

(2) remove a master node with slot

You need to move all the slot of this node to another master, and then delete it

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb info 172.16.101.54 slots 6379172.16.101.54 slots 6379 (610aa838...)-> 3 keys | 7220 slots | 1 slaves.172.16.101.66:6379 (58a08DFF...)-> 0 keys | 866 slots | 0 slaves.172.16.101.55:6379 (4c7348ac...)-> 1 keys | 4096 slots | 1 slaves.172.16.101.56:6379 (ece3a80f. .)-> 1 keys | 4202 slots | 1 slaves. [OK] 5 keys in 4 masters.0.00 keys per slot on average. [root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb reshard 172.16.101.54 master 6379 > Performing Cluster Check (using node 172.16.101.54 slots:866 6379) M: 610aa83831404be545b25cc7f7322e987da1dd33 172.16.101.54 slots:866-6826 additional replica (s) S: b50ba506525ee547823b3d9a7e5a095933e3ff42 172.16.101.59 6379 slots: (0 slots) slave replicates 4c7348ac575a1a3bd4357e937a8f94f1654193cfM: 58a08dff7169bb0ce289c19a6520c85131bb44da 172.16.101.66 slots:0-865 (866 slots) master 0 additional replica (s) S: 28e8d5c8fd12533622d8110f8d262cb50120ca02 172.16.101.58 slots 6379 slots: (0 slots) slave replicates 610aa83831404be545b25cc7f7322e987da1dd33M: 4c7348ac575a1a3bd4357e937a8f94f1654193cf 172.16.101.55 slots:6827-10922 (4096 slots) master 1 additional replica (s) M: ece3a80f6989fa7f8316d73ee30ceea84340f24e 172.16.101.56 master 6379 slots:12182-16383 (4202 slots) master 1 Additional replica (s) S: c79de1092011ed395ee772969274c0567c2b5dd1 172.16.101.60 slots: (0 slots) slave replicates ece3a80f6989fa7f8316d73ee30ceea84340f24e [OK] All nodes agree about slots configuration. > > Check for open slots... > Check slots coverage... [OK] All 16384 slots covered.How many slots do you want to move (from 1 to 16384)? 866What is the receiving node ID?610aa83831404be545b25cc7f7322e987da1dd33Please enter all the source node IDs. 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:58a08dff7169bb0ce289c19a6520c85131bb44daSource node # 2:done.Moving slot 864 from 58a08dff7169bb0ce289c19a6520c85131bb44daMoving slot 865 from 58a08dff7169bb0ce289c19a6520c85131bb44daDo you want to proceed with the proposed reshard plan (yes/no)? Moving slot 0 from 172.16.101.66 to 172.16.101.54:6379:Moving slot 2 from 172.16.101.66 to 172.16. [root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb info 172.16.101.54 keys 6379172.16.101.54 keys 6379 (610aa838...)-> 3 slaves | 8086 slots | 1 slaves.172.16.101.66:6379 (58a08df...)-> 0 keys | 0 slots | 0 slaves.172.16.101.55:6379 (4c7348ac...)-> 1 keys | 4096 slots | 1 slaves. 172.16.101.56 ece3a80f... 6379 (ece3a80f...)-> 1 keys | 4202 slots | 1 slaves. [OK] 5 keys in 4 masters.0.00 keys per slot on average. [root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb del-node 172.16.101.54 slots 6379 '58a08dff7169bb0ce289c19a6520c85131bb44da'

Upgrade the Redis node

If it's Slave, you can just stop it and replace it with a higher version.

If it is Master, you can switch the master to slave through cluster failover, then upgrade, and finally execute cluster failover manually.

Migrate slot data

(1) create three keys belonging to one slot and migrate these keys to a new node. If the key name contains {}, only the strings included in {} are calculated when calculating the hash value, so the following three key belong to the same slot.

172.16.101.54 located at 172.16.101.66:6379OK172.16.101.66:6379 6379 > SET key: {test}: 555 value:test:555- > Redirected to slot [6918] located at 172.16.101.66:6379OK172.16.101.66:6379 > SET key: {test}: 666 value:test:666OK172.16.101.66:6379 > SET key: {test}: 777 value:test:777OK172.16.101.54:6379 > CLUSTER KEYSLOT key: {test}: 555 (integer) 6918172.16.101.54Redirected to slot 6379 > CLUSTER KEYSLOT key: {test}: 666 (integer) 6918172.16.101.54 cluster getkeysinslot 6379 > CLUSTER KEYSLOT key: {test}: 777 (integer) 69182.16.101.55 cluster getkeysinslot 6379) "key: {test}: 555" 2) "key: {test}: 666" 3) "key: {test}: 777"

(2) the purpose is to move the slot6918 on the IP172.16.101.55 to the IP172.16.101.66 node

172.16.101.56 cluster nodes1e905d0573c5c71b6b8e3cf2af92584da78d1be2 172.16.101.59 slave 6f529643c9fb12075014ae9c9aced50f23bb3127 01533464714919 5 connected2fb7f7439771771f37f1e52add0bbaea5b196786 172.16.101.58 slave 6f529643c9fb12075014ae9c9aced50f23bb3127 01533464715920 4 connected6f529643c9fb12075014ae9c9aced50f23bb3127 172.16.101.54 connected6f529643c9fb12075014ae9c9aced50f23bb3127 6379 master-01533464711913 1 connected 0-5460eac2a7e96f8c4f03b8b2e44ec79b274153417951 172.16.101.55 connected 6379 master-01533464717926 2 connected 5461-10922243b0c9ab7532427536bb5662db7c57030250798 172.101.60 slave 64d6aac9b175066fbf8138dc99662778dda4084b 01533464716924 6 connected64d6aac9b175066fbf8138dc99662778dda4084b 172.16.101.56

Import slot 6918 on the target node 172.16.101.56

172.16.101.56 cluster setslot 6379 > cluster setslot 6918 importing eac2a7e96f8c4f03b8b2e44ec79b274153417951172.16.101.56:6379 > cluster nodes64d6aac9b175066fbf8138dc99662778dda4084b 172.16.101.56 cluster nodes64d6aac9b175066fbf8138dc99662778dda4084b 6379 myself,master-003 connected 10923-16383 [6918-cluster setslot 6918 migrating 64d6aac9b175066fbf8138dc99662778dda4084b172.16.101.55:6379 > cluster nodeseac2a7e96f8c4f03b8b2e44ec79b274153417951 172.16.101.55 Para6379 myself Master-00 2 connected 5461-10922 [6918->-64d6aac9b175066fbf8138dc99662778dda4084b] 172.16.101.55 key 6379 > migrate 172.16.101.56 6379 "0 1000 keys key: {test}: 777 key: {test}: {test}: 555172.16.101.55 ASK 6379 > MGET key: {test}: 777 key: {test}: {test}: 555 (error) ASK 6918 172.16.101.56

Execute the migration command on all master

172.16.101.54 connected 6379 > cluster setslot 6918 node 64d6aac9b175066fbf8138dc99662778dda4084b172.16.101.55:6379 > cluster setslot 6918 node 64d6aac9b175066fbf8138dc99662778dda4084b172.16.101.56:6379 > cluster setslot 6918 node 64d6aac9b175066fbf8138dc99662778dda4084b172.16.101.54:6379 > cluster nodeseac2a7e96f8c4f03b8b2e44ec79b274153417951 172.16.101.55 cluster setslot 6379 master-01533466116633 2 connected 5461-69176919-1092264d6aac9b175066fbf8138dc99662778dda4084b 172.16.101.56 connected 6379 myself-015334661146293 connected 691810923-163831e905d0573c5c71b6b8e3cf2af92584da78d1be2 172.16.101.59 connected 6379 slave eac2a7e96f8c4f03b8b2e44ec79b274153417951 01533466115630 5 connected6f529643c9fb12075014ae9c9aced50f23bb3127 172.16.101.54 Master-0 01 connected 0-54602fb7f7439771771f37f1e52add0bbaea5b196786 172.16.101.58 slave 6f529643c9fb12075014ae9c9aced50f23bb3127 0 1533466113626 4 connected243b0c9ab7532427536bb5662db7c57030250798 172.16.101.60 connected243b0c9ab7532427536bb5662db7c57030250798 01533466112623 6 connected

Finally, you can check whether the migration is successful through the check command.

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb check 172.16.101.54:6379

FAQ

Error1:

[root@sht-sgmhadoopcm-01 redis] # src/redis-trib.rb check 172.16.101.54:6379

.

[OK] All nodes agree about slots configuration.

> Check for open slots...

[WARNING] Node 172.16.101.54 has slots in migrating state 6379.

[WARNING] Node 172.16.101.66 has slots in importing state.

[WARNING] The following slots are open: 866

> Check slots coverage...

[OK] All 16384 slots covered.

Solution:

Log in to the corresponding two redis services to execute:

172.16.101.54 stable 6379 > cluster setslot 866

OK

172.16.101.66 stable 6379 > CLUSTER SETSLOT 866

OK

Reference link

Https://redis.io/topics/cluster-tutorial

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report