redis-sentinel-Sentinel Cluster-Simple Deployment

Keywords: Operation & Maintenance Redis

Main functions of Redis Sentinel

Sentinel's main functions include primary node survival detection, master-slave operation detection, automatic failover, master-slave switching. The minimum configuration of entinel in Redis is one master and one slave.

The entinel system of Redis can be used to manage multiple Redis servers. The system can perform the following four tasks:

Monitor

Sentinel constantly checks whether the master and slave servers are functioning properly.

notice

Sentinel sends notifications to administrators or other applications through API scripts when a Redis server under monitoring has problems.

Automatic failover

When the master node does not work properly, Sentinel will start an automatic fault transfer operation. It will upgrade one of the slave nodes in which the failed master node is a master-slave relationship to a new master node, and point other slave nodes to the new master node.

Configuration Provider

In Redis Sentinel mode, when the client application is initialized, it connects to the Sentinel node set, from which the information of the primary node is obtained.

Subjective and objective offline

By default, each Sentinel node sends PING commands to Redis nodes and other entinel nodes at a frequency of once a second, and determines whether the node is online by the reply of the node.

Subjective Offline

Subjective offline is applicable to all master and slave nodes. If Sentinel does not receive a valid response from the target node within milliseconds of down-after-milliseconds, it will determine that the node is subjectively offline.

Objective Offline

The objective offline is only applicable to the primary node. If the primary node fails, the Sentinel node will ask other Sentinel nodes for their status judgement by sentinel is-master-down-by-addr command. If the number of nodes exceeding < quorum > determines that the primary node is not reachable, the Sentinel node will judge that the primary node is objective downline.

The schematic diagram is as follows

master, slave configuration file content

cat 6380/redis-6380.conf

port 6380
logfile "./redis-6380"
#Daemon process model
daemonize yes

cat 6381/redis-6381.conf 

port 6381
logfile "./redis-6381"
daemonize yes
replicaof 127.0.0.1 6380

sentinel configuration file content

cat 26379/redis-sentinel.conf


port 26379
# Daemon process model
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile /var/log/redis/sentinel.log
dir /tmp
# Sentinel monitors the master, marking master as odown after at least quorum sentry instances think master down
# (objective down objectively; corresponding to the existence of sdown, subjective down, subjective down) state.
# Slves are automatically discovered, so you don't need to specify them explicitly.
sentinel monitor mymaster 127.0.0.1 6379 2
# How long does master or slave last (default 30 seconds) and cannot be marked as s_down.
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
# If sentinel failover operation is not completed within this configuration value (i.e. master/slave automatic switching in case of failure), it is considered that this failover failed.
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

cat 26380/redis-sentinel.conf

port 26380
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile /var/log/redis/sentinel.log
dir /tmp
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
 
cat 26381/redis-sentinel.conf

port 26381
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile /var/log/redis/sentinel.log
dir /tmp
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

Start up services

redis-server 6380/redis-6380.conf 
redis-server 6381/redis-6381.conf 
redis-server 26379/redis-sentinel.conf --sentinel
redis-server 26380/redis-sentinel.conf --sentinel
redis-server 26381/redis-sentinel.conf --sentinel
#The configuration file will be modified after startup

Verify cluster status

#Connect to sentinel node

redis-cli -h 127.0.0.1 -p 26381

#Query primary node status

127.0.0.1:26381> SENTINEL get-master-addr-by-name mymaster
1) "127.0.0.1"
2) "6380"

#Query Sentinel Status

127.0.0.1:26381> info sentinel
# Sentinel

sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6380,slaves=1,sentinels=3

#Simulate the failure to shut down the master node process
#Query again

127.0.0.1:26381> SENTINEL get-master-addr-by-name mymaster
1) "127.0.0.1"
2) "6381"

#Successful handover
#Verification success

Reference material

https://www.cnblogs.com/bingshu/p/9776610.html Blog
https://redis.io/topics/sentinel Official website information

Posted by mr666 on Wed, 04 Sep 2019 22:55:27 -0700