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

The principle and configuration of Redis Sentinel Sentinel Mode

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article mainly introduces "the principle and configuration of Redis Sentinel Sentinel Mode". In daily operation, I believe many people have doubts about the principle and configuration of Redis Sentinel Sentinel Mode. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the principle and configuration of Redis Sentinel Sentinel Mode". Next, please follow the editor to study!

one。 Installation configuration

Add a sentinel to an environment with 1 master and 1 slave

Go to the redis source installation directory copy sentinel.conf file

# cd / u01/packages/redis-3.0.6

# cp sentinel.conf / usr/local/redis/etc/

# vi / usr/local/redis/etc/sentinel.conf

Daemonize yes

Sentinel monitor mymaster 127.0.0.1 6379 1

Sentinel down-after-milliseconds mymaster 30000

Sentinel parallel-syncs mymaster 1

Sentinel failover-timeout mymaster 180000

Parameter explanation:

Sentinel monitor mymaster 127.0.0.1 6379 1

Instruct Sentinel to monitor a master named mymaster, which can be specified as any name

Master IP is 127.0.0.1, port number is 6379

This master determines that at least one Sentinel consent is required for failure (as long as the number of agreed Sentinel is not up to standard, automatic failover will not be performed)

Note that no matter how many Sentinel agreements you set to determine a server failure, a Sentinel needs the support of a majority of (majority) Sentinel in the system to initiate an automatic failover.

Sentinel down-after-milliseconds mymaster 30000

Down-after-milliseconds specifies the number of milliseconds that Sentinel thinks master has been disconnected

Sentinel parallel-syncs mymaster 1

Parallel-syncs specifies the maximum number of slave that can synchronize the new master at the same time when performing a failover, and the smaller this number, the longer it takes to complete the failover

Sentinel failover-timeout mymaster 180000

Failover-timeout specifies the number of milliseconds allowed for failover. After this time, the failover is considered to have failed. The default is 3 minutes.

Start sentinel

# redis-sentinel / usr/local/redis/etc/sentinel.conf

View statu

# redis-cli-p 26379

127.0.0.1purl 26379 > info sentinel

# Sentinel

Sentinel_masters:1

Sentinel_tilt:0

Sentinel_running_scripts:0

Sentinel_scripts_queue_length:0

Master0:name=mymaster,status=ok,address=127.0.0.1:6379,slaves=1,sentinels=1

At this point, the configuration sentinel work is complete.

Sentinel related commands

Basic status information of INFO sentinel

PING: returns PONG

SENTINEL masters: lists all monitored master and the current status of these master

SENTINEL slaves: lists all slave servers for a given master and the current status of these slave

SENTINEL get-master-addr-by-name: returns the IP address and port number of the master with the given name. If the master is performing a failover operation, or if the failover operation for this master has been completed, this command returns the IP address and port number of the new master.

SENTINEL reset: resets all master whose names match the given pattern pattern. The pattern parameter is a Glob-style pattern. The reset operation clears all current states of master, including ongoing failover, and removes all slave and Sentinel of master that have been discovered and associated so far

SENTINEL failover: when master fails, force an automatic failover without consulting other Sentinel (although the Sentinel initiating the failover will send a new configuration to other Sentinel, and the other Sentinel will update accordingly).

two。 Principle:

There are two main problems to be solved during failover: one is to choose Leader Sentinel, the other is to choose a new master.

1. Select the Leader Sentinel rule

Sentinel automatic failover uses the Raft algorithm to elect a leader (Leader) Sentinel, ensuring that only one Leader is generated in a given era (epoch).

Indicates that in the same period, no two Sentinel will be selected as Leader at the same time, and each Sentinel will vote for only one Leader in the same period.

Note: the main idea of the Raft algorithm is to reach an agreement on the principle of minority obeying the majority in the same Term (Epoch) vote, and select Leader.

The specific algorithm is not explained too much here. For details, please refer to the article: https://www.jianshu.com/p/8e4bbe7e276c

two。 Select a new master rule

1 > among the slave servers under the failed master server, those slaves marked as subjectively offline, disconnected, or whose last reply to the PING command took more than five seconds will be eliminated.

2 > among the slave servers under the failed master server, those slave servers that have been disconnected from the failed master server for more than ten times the time specified by the down-after option will be eliminated.

3 > among the remaining slave servers after the above two rounds of elimination, we select the slave with the largest replication offset (replication offset) as the new master server; if the replication offset is not available, or if the replication offset of the slave server is the same, then the slave server with the minimum running ID becomes the new master.

A failover step:

1 > it is found that master has entered an objective offline state.

2 > add yourself to the current era (epoch) and try to be elected in this era.

3 > if elected fails, try to be elected again after twice the set failover timeout. If elected successfully, perform the following steps

4 > pick a slave and upgrade it to master.

5 > send the SLAVEOF NO ONE command to the selected slave to change it to master.

Through publish and subscribe capabilities, the updated configuration is propagated to all other Sentinel, and the other Sentinel updates their own configuration.

6 > send SLAVEOF host port commands to other slave that have been deactivated master and ask them to copy the new master.

7 > when all slave have started to copy the new master, the lead Sentinel terminates the failover operation.

At this point, the study on the principle and configuration of Redis Sentinel Sentinel mode is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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: 218

*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