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

How to realize the Sentinel Mode in Redis

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

Share

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

This article mainly introduces how to realize the sentinel mode in Redis. It is very detailed and has a certain reference value. Friends who are interested must finish it!

Redis Sentinel Sentinel mode is a distributed system where you can run multiple Sentinel processes (progress) in a single architecture, which use the rumor protocol (gossip protocols) to receive information about whether the master server is offline, and use the voting protocol (agreement protocols) to decide whether to perform automatic failover and which slave server to choose as the new master server. [related recommendation: Redis video tutorial]

Redis's Sentinel system is used to manage multiple Redis servers (instance) and the system performs the following three tasks:

Monitoring (Monitoring): Sentinel will constantly check whether your master server and slave server are working properly.

Reminder (Notification): when there is a problem with a monitored Redis server, Sentinel can send notifications to administrators or other applications through API.

Automatic failover (Automatic failover): when a master server does not work properly, Sentinel starts an automatic failover operation, which upgrades one of the slaves of the failed master server to the new master server and allows the other slave servers of the failed master server to replicate the new master server When the client tries to connect to the failed primary server, the cluster also returns the address of the new primary server to the client, so that the cluster can use the new primary server instead of the failed server.

Sentinel working mechanism

Each sentinel sends a PING command to its known master,slave and other sentinel instances at a frequency of once per second.

If the time from the last valid reply to a PING command to an instance exceeds the value specified by the down-after-milliseconds option, the instance will be marked by sentinel as subjectively offline.

If a master is marked as subjectively offline, all sentinel that are monitoring the master should confirm that the master has indeed entered the subjective offline state at a frequency of once per second.

When a sufficient number of sentinel (greater than or equal to the value specified in the profile) confirms that master has indeed entered the subjective offline state within a specified time range, the master will be marked as objective offline.

In general, each sentinel sends INFO commands to all master,slave it knows at a frequency of every 10 seconds

When master is marked as objective offline by sentinel, the frequency of sentinel sending INFO commands to all slave of offline master will be changed from 10 seconds to 1 second.

If there is not enough sentinel to agree that master has been offline, the objective offline status of master will be removed; if master returns a valid reply to sentinel's PING command, the subjective offline status of master will be removed.

Sentinel schema building

Environment

Master:127.0.0.1:6379 [initialize master] slave:127.0.0.1:6380 127.0.0.1:6381sentinel:127.0.0.1:26379 127.0.0.1 slave:127.0.0.1:6380 127.0.0.1:6381sentinel:127.0.0.1:26379 26380 127.0.0.1

Modify the configuration:

Omit the installation of redis here and modify the sentinel configuration file directly. Corresponding folder Redis6379-Redis6381

# Monitor the node and fail over more than 2 sentinel tasks before performing a failover sentinel monitor mymaster 127.0.0.1 6379 "if the node does not respond within 30000 milliseconds, it is considered that the failure sentinel down-after-milliseconds mymaster 3000 is considered to be a timeout sentinel failover-timeout mymaster 180000sentinel deny-scripts-reconfig yes with master-slave replication of 1sentinel parallel-syncs mymaster cycles after the failover.

Start command

. / src/redis-sentinel. / config/redis-sentinel-6379.conf (also launched 6380 6381) these are all the contents of the article "how to implement the Sentinel Mode in Redis". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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