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

What is Redis Sentinel mode?

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is Redis Sentinel Mode". The content of the explanation 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 is Redis Sentinel Mode".

Sentinel mode 1. Sentinel concept

In the one-master-multi-slave architecture, if the master goes down, you need to choose one of several slave as the new master. To accomplish this function, you need to use Redis's sentinel mechanism.

Sentinel is a distributed system that monitors each server in the master-slave structure, selects a new master through a voting mechanism and connects all slave to the new master in the event of a failure, as shown in the following figure:

two。 Sentinel function

Monitoring: monitoring master and slave

Constantly check whether master and slave are running properly.

Master Survival Detection, master and slave Operation Detection

Notification (reminder): when there is a problem with the monitored server, send a notification to other sentinels and Redis servers

Failover: disconnect the down master from the slave, select a slave as the master, connect the other slave to the new master, and inform the client of the new server address

Note: the Sentinel is also a redis server, which only provides monitoring services, not data management services; usually the number of Sentinels is configured as odd (to facilitate voting)

3. Activate the sentinel.

Modify the Sentinel's configuration file sentinel.conf, which is located in the Redis directory, as shown in the following figure:

The meaning of partial configuration is shown in the following figure:

Activate the sentinel.

Redis-sentinel filename # filename refers to the configuration file name # each Sentinel has to configure his or her own profile

After configuring and starting the sentinel, when the master server goes down, voting and master-slave switching will be performed automatically.

4. Sentinel principle

The Sentinel goes through three stages in the master-slave switching process:

Monitor and control

Notice

Fail-over

4.1 Monitoring

It is used to synchronize the status information of each node, including master, slave, Sentinel, that is, the information of all servers in the whole system.

Main completed functions:

Get the status of each sentinel (online): the newly added Sentinel will exchange information with the Sentinel that already exists in the system.

Get the status of the master (through the info instruction)

The content obtained is as follows

1. Master attribute runid role:master2. Basic information saved by each slave in master

Get the status of all slave (send info instructions to all slave based on the information of slave in master)

The content obtained is as follows

Slave properties runid role:slave master_host, master_port offset

The specific internal working principles are as follows:

After Sentinel 1 sends info commands to master, a cmd connection is established, which is used to send commands.

After creating a cmd connection, Sentinel 1 will save all the information he has obtained so far, and the master on the other side will also keep the information he holds.

Then Sentinel 1 sends info instructions to slave according to the information about salve obtained from master, obtains the information of salve, and enriches the information saved at this end.

When a new Sentinel 2 is added, Sentinel 2 sends an info command to master to establish a cmd connection. Sentinel 1, which already exists, can be obtained according to the information in master, and the obtained information is saved on its own side. Then determine whether Sentinel 1 is online, establish a connection with Sentinel 1, the two exchange their own information, and the two sides will continue to ping to ensure that they are smooth.

Sentinel 2 enriches its saved information based on the slave information obtained from master and the information obtained from slave.

Another Sentinel 3 was added, which was similar to the previous process, and finally the three Sentinels established a network.

The three parties in the relationship network will exchange and send information to each other. This kind of working mode in the relationship network is called publish and subscribe mode.

4.2 Notification

In the notification phase, the Sentinels constantly get the information of master and slave, and then share the information among the Sentinels.

The specific process is as follows:

Through the established cmd connection, the Sentinel sends hello instructions to master and slave, gets their information, and then shares them in the network:

4.3 failover

Disconnect the down master from the slave, select a slave as the master, connect the other slave to the new master, and inform the client of the new server address.

The specific process is as follows:

Sentinel 1 never got a response from master, subjectively judged that master was down and marked sdown (only one Sentinel thought master was down)

Sentinel 1 sends messages in the network, sending messages to other sentinels in the upper left corner of the picture.

After receiving the message, all other sentinels send messages to master to determine whether master is down, and they will also send their own results to other sentinels in the network. After determining that master is down, change the mark to odown (after all Sentinel detection, more than half of Sentinels think that master is down)

When the master is determined to be down, it is necessary to elect a new master, and it is up to the sentry to decide which sentinel will do this through the election between the sentinels, as follows:

During the election, each sentry has one vote, and each sentinel will issue a command to tell other sentinels in the intranet that they will be electors. For example, sentinel1 and sentinel2 issue this election order. After sentinel3 receives their application, sentinel3 will vote for one of the parties, and the party who gets the vote will have one more vote according to the order of arrival, according to this form. In the end, there will be an election result, and the sentry who gets the most votes will be elected.

In this process, there may be defeats. For example, if the first round is not successful, the second and third round will be held until the election is completed.

When the election between the sentinels is completed, the winning sentinel will then go to the slave to select one and turn it into the new master. The specific process is as follows:

Offline OUT

Slow response OUT

OUT that has been disconnected from the original master for a long time

End of exclusion, start selection

Those with high priority are selected.

The larger offset is selected (larger means that synchronizing the original master has the most data)

If it has not been selected yet, it will be finally selected according to runid.

Sentinel's principle for selecting alternative master from the server list: exclude first, then select

After selecting a new master, the sentry sends instructions to the server:

Send slaveof no one instructions to the new master

Send slaveof new masterIP port instructions to other slave

At the same time, tell the other sentinels who the new master is.

Thank you for your reading, the above is the content of "what is Redis Sentinel Mode". After the study of this article, I believe you have a deeper understanding of what Redis Sentinel Mode is, 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.

Share To

Database

Wechat

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

12
Report