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

Master-slave relationship adjustment of Redis cluster nodes

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

1. After the Redis cluster is created, it may occur that the nodes with master-slave relationship are subordinate to the same server. In this case, if the server goes down or needs downtime and maintenance, the master-slave nodes stop running at the same time, resulting in the temporary loss of some slot slots in the redis cluster. At this point, the redis cluster is in the state of fail, and the data read and write operations cannot be performed normally. In order to avoid this situation, the master-slave relationship of redis cluster nodes should be adjusted so that the master-slave nodes belong to different servers. Two. adjustment method description 1. Use the redis-trib.rb script to remove the slave nodes to be adjusted from the redis cluster. (when you do this, the slave node is removed from the redis cluster. At the same time, the slave node process is killed. ) the command is as follows: a node in the redis-trib.rb del-node cluster IP:PORT the slave node ID2 to be adjusted. Delete all files under the RDB subdirectory of the slave node to be adjusted. (includes "dump.rdb" and "nodes- node port number .conf" files. ) 3. Restart the slave node to be adjusted. 4. Use the redis-trib.rb script to add the slave node to be adjusted to the redis cluster to make it correspond to the appropriate master node and establish a new master-slave relationship. The command is as follows: redis-trib.rb add-node-- slave-- master-id master node ID A node in the IP:PORT cluster to be adjusted IP: Port 3. Specific operation method example 1.redis cluster node master-slave relationship chart-redis cluster node master-slave relationship

Master node information slave node information

Master node ID master node address slave node ID slave node address 487247ac4e34c0102d54eaca3256dce9b24667f4132.46.115.146:658023b674847132d82c355b3f440aa3f1f940316b69132.46.115.148:65813e745792f2a1f179501aea3264186aa55103a434132.46.115.148:658006b296c1d87fbf69638076d53054d89bd15ef2ad132.46.115.146:65812d93e76a04d20ca0a91e22694201f3b4b18c740b132.46.115.149:6580f8a342695baac0bce608ed468f2414c2e68abc49132.46.115.149:6581

Table 1 Master-slave relationship of redis cluster nodes

It can be seen from figure 1 and Table 1 that a pair of master-slave nodes (132.46.115.149purl 6580 and 132.46.115.149purl 6581) are subordinate to the same server. You need to remove two slave nodes (including 132.46.115.149) from the redis cluster, and then establish a new master-slave relationship. The specific operation methods are as follows. (1) remove two slave nodes from the redis cluster (132.46.115.146f8a342695baac0bce608ed468f2414c2e68abc49 6581 and 132.46.115.149f8a342695baac0bce608ed468f2414c2e68abc49 6581) execute the following two commands on either server: redis-trib.rb del-node 132.46.115.146 6580 f8a342695baac0bce608ed468f2414c2e68abc49 (2) delete all files under the RDB subdirectory of the two slave nodes at 132.46.115.146 and 132.46.115.146 respectively Execute the following command on the 132.46.115.149 server: rm ${REDIS_CLUSTER_HOME} / redis6581/rdb/* (3) restart the deleted two slaves on the 132.46.115.146 and 132.46.115.149 servers, respectively: ${REDIS_CLUSTER_HOME} / redis6581/bin/redis-server ${REDIS_CLUSTER_HOME} / redis6581/conf/redis.conf (4) the two slaves to be deleted Join the redis cluster and establish a new master-slave relationship on any server. Execute the following two commands on any server: redis-trib.rb add-node-- slave-- master-id 2d93e76a04d20ca0a91e22694201f3b4b18c740b 132.46.115.146 132.46.115.146:6580redis-trib.rb add-node 6581 132.46.115.146:6580redis-trib.rb add-node-- slave-- master-id 3e745792f2a1f179501aea3264186aa55103a434 132.46.115.149 master-id 2d93e76a04d20ca0a91e22694201f3b4b18c740b 6581 132.46.115.146 master-id 2d93e76a04d20ca0a91e22694201f3b4b18c740b 6580

The adjusted redis cluster node relationship is shown in Table 2.

Master node ID master node address slave node address 487247ac4e34c0102d54eaca3256dce9b24667f4132.46.115.146:6523b674847132d82c355b3f440aa3f1f940316b69132.46.115.148:65813e745792f2a1f179501aea3264186aa55103a434132.46.115.148:6580f8a342695baac0bce608ed468f2414c2e68abc49132.46.115.149:65812d93e76a04d20ca0a91e22694201f3b4b18c740b132.46.115.149:658006b296c1d87fbf69638076d53054d89bd15ef2ad132.46.115.146:6581

Table 2 New master-slave relationship of redis cluster nodes

IV. Script that automatically detects the master-slave relationship of redis cluster nodes

Figure 2 script for automatically detecting the master-slave relationship of redis cluster nodes

Figure 2 is a script that automatically detects the master-slave relationship of redis cluster nodes. You need to pass in 2 parameters when executing this script. Parameter 1 is IP of any node in redis cluster, and parameter 2 is port of any node of redis cluster. If there is a situation where the master and slave nodes are subordinate to the same server, the information will be displayed in a red background. Otherwise, the information is displayed in a green background. The execution method and output of the script are shown in figure 3.

Figure 3 automatically detects the execution of master-slave relationship scripts of redis cluster nodes

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

Servers

Wechat

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

12
Report