In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the precautions for sentinel to build a high-availability redis cluster". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the precautions for sentinel to build a high-availability redis cluster?"
The official sentinel of redis is usually used when deploying a Redi high-availability cluster. Sentinel monitors master status and performs cluster master failover in case of master downtime. There are many ways to deploy online, and here are some things to pay attention to.
Set the same cluster password
For security, passwords are sometimes set for redis and sentinel. Because the cluster may switch, the password of the redis cluster should be the same. For the node with slave-priority set to 0, since it will not become master, the password can be set separately, not the same as other machines, as long as masterauth is set to the password of master.
Sentinel supports setting passwords in later versions of redis5. Since sentinel needs to communicate with each other, passwords must be the same throughout the sentinel cluster. Of course, you don't need to have the same password as the redis node.
Redis binds local IP
The bind instruction of the redis configuration file can be bound to multiple IP, which is 127.0.0.1 by default. If the sentinel is not local, you need to bind the redis to the public network IP, and the first IP bound to the bind must be accessible to the outside world.
The master-slave replication of redis requires communication between slave and master. When redis establishes a TCP connection to the outside world, it uses the first IP bound by bind as the local IP. If bind 127.0.0.1 1.1.1.1 is configured to access master, 127.0.0.1 master will be bound. If it is not local, the connection will fail.
The dir of the configuration file is placed before other path-related instructions
The dir instruction changes the relative path of the following instructions. If there are other instructions in the configuration that depend on the relative file path, such as pidfile or logfile, put these instructions after the dir instruction.
Disable the CONFIG instruction so that master cannot be switched
Redis's CONFIG directive modifies the local file, causing a security risk, while adding rename-command CONFIG "" to the configuration file can disable the CONFIG directive.
When sentinel detects master downtime for failover, it sends a transaction instruction (MULTI) to slave, including SLAVEOF and CONFIG instructions. The SLAVEOF instruction instructs slave to replace the master,CONFIG instruction to update the slaveof to the configuration file. If the CONFIG directive is disabled, the transaction fails and the corresponding slave cannot switch master.
IP of sentinel machine without public network needs to be specified through announce-ip
Both redis and sentinel support announce-ip and announce-port to declare ip and port. You need to specify this configuration if the IP provided for external services is not consistent with the egress for external access, especially now many CVMs can only be accessed via private network IP through slb.
Mutual discovery between sentinel is achieved by master. Sentienl broadcasts its own IP address to the channel of master's _ _ sentinel__:hello ", and other sentinel discovers other sentinel based on this message. If the sentienl machine is in the private network and the sentinel needs to be accessed through the public network, you need to configure the announce-ip as the IP accessible by the public network in the configuration file. Between redis, the address is obtained through the peer address of the TCP connection, and this problem does not exist.
Add a redis cluster with a password to a running sentinel
Sentinel gets the master information by reading the configuration file, and the running sentinel can also be configured by instructions.
When you can add a monitored cluster through sentinel monitor, if the cluster has a password, set it through the sentinel set cluster name auth-pass password. After setting it, you need to use the sentinel reset cluster name to allow sentinel to re-establish a TCP connection with the cluster master to take effect.
Do not manually execute slaveof on redis that has joined the cluster
Sentinel monitors the status of the nodes in the cluster. If you manually execute slaveof execution on the machines in the redis cluster, sentinel will resend the slaveof instruction after discovery to ensure the normal operation of the cluster.
Remove nodes from the cluster
If the node is slave, first shut down the node, and then send the sentinel reset cluster name reset cluster node information to all sentinel monitoring the cluster, completely remove the node from the cluster, and ensure that all sentinel execute this instruction, otherwise sentinel will re-send the slaveof instruction to join the cluster.
If the node is master, you need to switch master, and then follow the case of slave.
Remove the sentinel node in the same way as removing slave.
Redis cluster multi-level
Redis master-slave replication supports multiple levels, and if sentinel is used, the management of the cluster may be confused.
For example, node1 has two slave nodes node2 and node3,node2 have one slave node node4. If node1 goes down and sentinel switches the master of the cluster to node2, then node3 and node4 become at the same level. How should sentinel deal with it? However, there is no actual verification, and it is best to avoid this situation in cases of uncertainty.
How to choose slave during sentinel failover
When sentinel discovers that master is down, it sends INFO instructions to all slave every second to get the slave status in time. After that, you need to select a slave to upgrade to the cluster master.
When selecting slave, the slave that is normally connected and whose slave-priority is not 0 will be organized into an array, sorted by the slave-priority of the node from small to large, and the node with the same slave-priority value will be sorted according to the slave_repl_ offset value of the node (the offset of the slave_repl_offset master slave copy, the higher the value means that the data of the node is closer to the master). When the sorting is complete, select the first node in the array and promote it to cluster master.
Redis cluster data does not satisfy strong consistency.
Redis master-slave replication does not provide strong consistency, so data read from slave may be delayed with master. And data may be lost during master failover.
Senetinel does not care about the status and latency of redis master-slave replication, and selecting sentinel does not guarantee that the slave with the latest data will be promoted to master.
The newly deployed slave has no data until the synchronization is complete
After the newly deployed slave is connected to master, master generates a rdb file and transfers it to slave,slave to load the data in it. In this process, the slave is accessible to the outside world, so that the results requested during this period do not exist. Only when slave receives the rdb file, redis cannot serve the outside during the loading process.
Thank you for your reading. The above is the content of "what are the considerations for sentinel to build a high-availability redis cluster". After the study of this article, I believe you have a deeper understanding of what matters needing attention for sentinel to build a high-availability redis cluster, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.