In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to analyze the principle of Sentinel mode in Redis. Many people may not understand it very well. In order to make you understand better, the editor has summarized the following contents for you. I hope you can gain something according to this article.
This article will give you an in-depth understanding of the principle of Redis Sentinel mode, talk about what sentinel can do, start the sentinel method and Sentinel workflow, and hope to help you!
What is Redis sentinel?
Redis Sentinel is the official high availability solution for Redis. Redis Sentinel provides high availability for Redis. In practice, this means that using Sentinel, you can create a Redis cluster that can automatically fail over without human intervention against certain types of failures. [related recommendation: Redis video tutorial]
What can sentinel do?
1. Monitor the health status of redis cluster nodes (master+replica) and sentinel nodes
2. Automatic failover: if master fails, sentinel can fail over and notify the client to connect to the new master.
3. Notification: through api, you can send notifications to administrators, developers, and monitored redis instances that have failed.
4. Configuration Center: the client connects to sentinel,sentinel and can access master to return node information to the client.
3. Start sentinel method
1 、 redis-sentinel / path/to/sentinel.conf
2. Redis-server / path/to/sentinel.conf-sentinel
The sentinel.conf configuration is described as follows
# configure master node information to be monitored 2 represents a quorum function is to indicate how many sentinel nodes are required to agree that # master nodes are unreachable before marking them as objective offline # for example, if 5 sentinel instances quorum is set to 2, then 2 sentinel nodes consider master unreachable, # then one of them will initiate a failover # if at least three sentinels are reachable, the failover will be authorized and actually started. Sentinel monitor mymaster 127.0.0.1 6379 2 # only need to configure master sentinel to automatically detect slave information sentinel down-after-milliseconds mymaster 60000 # if the master does not respond to the ping command / or report an error within the specified time, it is considered to be subjectively offline. Sentinel failover-timeout mymaster 180000sentinel parallel-syncs mymaster 1 # specifies how many replica can synchronize data with master in parallel during failover. The smaller the failover, the longer the failover. The above configuration can be configured through SENTINEL SET command. To modify it in real time. Sentinel monitor resque 192.168.1.3 6380 4sentinel down-after-milliseconds resque 10000sentinel failover-timeout resque 180000sentinel parallel-syncs resque 5
Note:
Redis-sentinel must be started with a configuration file, and restart needs to be resumed according to the configuration file. Port 26379 is opened by default, and port access must be opened between sentinel to facilitate mutual access.
IV. Sentinel work flow
1. First of all, dynamic awareness is realized between sentinel through the pub/subscribe mechanism of redis.
Objective offline:
When the subjective offline node is the master node, the Sentinel node will seek the judgment of other Sentinel nodes on the master node by instructing sentinel is-masterdown-by-addr. When the number of quorum (quorum configured in sentinel configuration) is exceeded, the Sentinel node thinks that there is a problem with the master node, so it is objectively offline. Most of the Sentinel nodes agree to the offline operation, that is to say, objective offline.
Note that objective offline takes effect only for master nodes. It will trigger failover.
3The master is offline and needs to be failed over.
Here is divided into two steps, the first need to select the sentinel sentinel master node, through the sentinel master node for redis failover.
The first is the sentinel electing leaders. Use the raft algorithm (state consensus algorithm).
Each Sentinel node can become a Leader. When a Sentinel node confirms that the master node of the redis cluster is subjectively offline, it will request other Sentinel nodes to request that it be elected as Leader. If the requested Sentinel node has not agreed to the election request of other Sentinel nodes, it agrees to the request (the number of votes is + 1), otherwise it does not agree.
If a Sentinel node gets the lowest number of votes in Leader (the maximum number of quorum and Sentinel nodes / 2q1), then the Sentinel node is elected as Leader; or re-elected.
The core idea of Raft: first come, first served, minority subordinate to majority.
After sentinel elects the master node, the sentinel master node needs to elect the redis cluster master node to build a new cluster relationship.
The new redis master node is elected on the basis of:
1. Time to disconnect from sentinel. Filtering finds replica slaves that disconnects from the primary sentinel server for longer than the configured host timeout down-after-milliseconds
2. Copy priority. Give priority to those with low replica-priority.
3. If the priority is the same, the replication offset has been processed. The bigger the priority, this is more in line with the business scenario functionality.
4. If the replication offset is the same, it's up to running ID. Give priority to the small ones.
After selecting the master node, start maintaining the cluster relationship.
1. Sentinel node, send the slave no one command to the new master node to make it independent
2. Sentinel node, send slaveof ip port to other nodes and follow to the master node
V. Summary
According to the above analysis, sentinel can achieve automatic failover by means of regular monitoring, but sentinel still has some problems, such as the possibility of data loss in the case of a single master node, and there is no ability to scale out if the performance of a single machine is limited.
After reading the above, do you have any further understanding of how to interpret the principle of Sentinel mode in Redis? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.