Home >Database >Redis >Detailed explanation of Redis sentry mode

Detailed explanation of Redis sentry mode

藏色散人
藏色散人forward
2020-09-15 09:20:382603browse

The following column Redis Tutorial will introduce to you about the implementation of ranking list in java based on redis ordered collection. I hope it will be helpful to friends in need!

Detailed explanation of Redis sentry mode

Sentinel is an independent process.
Principle: The sentinel monitors multiple running Redis instances by sending commands and waiting for the Redis server to respond.

Detailed explanation of Redis sentry mode

The role of the sentry:

  • By sending commands, let the Redis server return to monitor its running status, Including master server and slave server.
  • When Sentinel detects that the master is down, it will automatically switch the slave to the master, and then notify other slave servers through Publish and Subscribe Mode, modify the configuration file, and let them switch hosts.

However, problems may arise when a sentinel process monitors the Redis server. For this reason, we can use multiple sentinels for monitoring. Each sentinel will also be monitored, thus forming a multi-sentinel mode.

Failover (failover)

Assuming that the main server is down and Sentinel 1 detects this result first, the system will not immediately perform the failover process, only Sentinel 1 Subjectively believing that the main server is unavailable, this phenomenon becomes Subjective offline. When the subsequent sentinels also detect that the main server is unavailable and the number reaches a certain value, a vote will be held between the sentinels. The result of the vote will be initiated by one sentinel to perform a failover operation. After the switch is successful, each sentry will use the publish and subscribe mode to switch the slave server it monitors to the host. This process is called Objective offline. This way everything is transparent to the client.

Configuring Sentinel Mode

Configure 3 sentinels and a Redis server with 1 master and 2 slaves to demonstrate this process.


Service type Is it the main server IP address Port
Redis is 192.168.11.128 6379
Redis No 192.168.11.129 6379
Redis No 192.168.11.130 6379
Sentinel - 192.168.11.128 26379
Sentinel - 192.168.11.129 26379
Sentinel - 192.168.11.130 26379

Detailed explanation of Redis sentry mode

##Multi-sentinel monitoring Redis

First configure the master and slave servers of Redis, modify the redis.conf file as follows

# 使得Redis服务器可以跨网络访问
bind 0.0.0.0# 设置密码
requirepass "123456"# 指定主服务器,注意:有关slaveof的配置只是配置从服务器,主服务器不需要配置
slaveof 192.168.11.128 6379# 主服务器密码,注意:有关slaveof的配置只是配置从服务器,主服务器不需要配置
masterauth 123456
The above content is mainly to configure the Redis server. The slave server has one more slaveof configuration and password than the master server.

Configure 3 sentinels, and the configuration of each sentinel is the same.

There is a sentinel.conf file in the Redis installation directory (copy 3 copies)

# 禁止保护模式protected-mode no# 配置监听的主服务器,这里sentinel monitor代表监控,mymaster代表服务器的名称,可以自定义,192.168.11.128代表监控的主服务器,6379代表端口,2代表只有两个或两个以上的哨兵认为主服务器不可用的时候,才会进行failover操作。sentinel monitor mymaster 192.168.11.128 6379 2# sentinel author-pass定义服务的密码,mymaster是服务名称,123456是Redis服务器密码# sentinel auth-pass <master-name> <password>sentinel auth-pass mymaster 123456</password></master-name>
The protection mode is turned off for testing.

With the above modifications, we can enter the src directory of the Redis installation directory and start the server and sentinel through the following commands

# 启动Redis服务器进程./redis-server ../redis.conf
# 启动哨兵进程./redis-sentinel ../sentinel.conf
Pay attention to the startup sequence.

First is the Redis service process of the host (192.168.11.128), then start the service process of the slave, and finally start the three sentinel service processes.

The above is the detailed content of Detailed explanation of Redis sentry mode. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete