Home  >  Article  >  Database  >  How to ensure high availability of redis

How to ensure high availability of redis

(*-*)浩
(*-*)浩Original
2019-11-20 14:49:503288browse

How to ensure high availability of redis

#redis high availability: If you deploy a master-slave architecture, you just need to add sentinels, and you can achieve it if any instance goes down. , active and standby switching will be performed automatically.

# Sentinel Machine (Recommended learning: redis video tutorial )

After the realization of the master and slam The server is monitored, and a "sentinel" mechanism is provided after redis2.6. As the name suggests, the meaning of sentinel is to monitor the running status of the redis system. Multiple sentinels can be started to monitor the running status of the redis database. Its main functions have two points:

a. Monitor whether all node databases are running normally.

b. When the master database fails, a new master can be automatically elected from the slave node through the voting mechanism to achieve automatic switching from the slave database to the master database.

In a Redis system with one master and multiple slaves, multiple sentinels can be used to perform monitoring tasks to ensure that the system is robust enough. At this time, not only will the sentinel monitor the master database and the slave database at the same time, but the sentinels will also monitor each other. Here, it is recommended that you deploy at least 3 sentries and use an odd number of sentries.

The Sentinel system of Redis is used to manage multiple Redis servers. The system performs the following three tasks:

Monitoring: Sentinel will constantly check whether your Master and Slave are operating normally.

Notification:When there is a problem with a monitored Redis, the sentinel can send notifications to the administrator or other applications through the API.

Automatic failover:When a Master fails to work properly, Sentinel will start an automatic failover operation, and it will upgrade one of the Slaves of the failed Master. As the new Master, and let other Slaves of the failed Master change to copy the new Master; when the client tries to connect to the failed Master, the cluster will also return the address of the new Master to the client, so that the cluster can use the Master to replace the failed Master.

Sentinel is a distributed system. You can run multiple sentinel processes in an architecture. These processes use gossip protocols to receive information about whether the Master is offline information, and use voting protocols (agreement protocols) to decide whether to perform automatic failover and which Slave to choose as the new Master.

Each sentinel will report to other sentinels, The master and slave regularly send messages to confirm whether the other party is "alive". If the other party does not respond within the specified time (configurable), the other party is temporarily considered to be down (the so-called "subjective downtime"). Subjective Down, referred to as sdown ).

If most sentinels in the "Sentinel Group" report that a certain master is not responding, the system will consider the master to be "completely dead" (ie: objectively down, Objective Down, referred to as odown) ), through a certain vote algorithm, select one of the remaining slave nodes to be promoted to master, and then automatically modify the relevant configuration.

Although sentinel is released as a separate executable file redis -sentinel, but in fact it is just a Redis server running in a special mode. You can start sentinel by giving the --sentinel option when starting a normal Redis server.

The above is the detailed content of How to ensure high availability of redis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn