Detailed explanation of redis sentinel architecture

what is redis sentinel

This article only talks about what the redis sentinel is. I mentioned a high availability repeatedly in the redis master-slave architecture, that is, when our master node goes down and hangs, we will elect a slave to promote the master to ensure our service. availability. Redis sentinel is an implementation of redis high availability officially provided by redis. Its function is what we mentioned above. It can monitor our nodes, perform a perfect migration process mentioned above, and notify our customers. end.

        For example, when the master is down, we execute the slaveof no one command on a slave to make the slave node no longer belong to any master and become the master itself, and the other slaves execute the slaveof new master command to synchronize the new master, but there will be This is a problem, we don't know when the master node will be unavailable, we can't solve it manually in time, and we are easy to be in a hurry when this kind of problem occurs. And how do we notify our clients when the master changes? Then you can use redis sentinel.

Let's take a picture to illustrate the architecture of sentinel:

        First of all, you can imagine a sentinel as a redis process, the difference is that sentinel is not responsible for storing data, it is responsible for a fault judgment, failover and notification client functions for redis. In addition, it can be seen from the above figure that there are not one but multiple sentinels, which can ensure a fairness for us to judge the fault (several sentinels can be set later to think that the node is faulty), and it also ensures that our high Available (that is, when a sentinel node hangs, we can still guarantee that our sentinel mechanism is perfect).

        Then the client will never get information directly from redis, that is to say, the address of redis (a certain IP) will not be recorded in our client, but the address of sentinel, so that we can directly from The redis address obtained by sentinel, because sentinel monitors all masters and slaves, it knows who is the real master. For example, we fail over. At this time, for sentinel, the master has changed, and then notify client. The client does not need to care who is the real master at all, but only cares about the master notified by sentinel.

Steps for redis sentinel failover

1. Multiple sentinels found and confirmed that there is a problem with the master.

2. Elect a sentinel as the leader. (Because the failover sequence of operations only needs one sentinel to complete)

3. Select a slave from multiple slaves as the new master

4. Notify the remaining slaves to become the slaves of the new master

5. Notify the client of the master-slave change (so that the client will not have the problem of read failure)

6. Wait for the resurrection of the old master to become the slave of the new master (sentinel will still monitor the old master for resurrection)

Here is a brief mention: our set of sentinel can monitor the combination of multiple sets of master+slave, which can effectively save resources, and each set of master+slave will use a master-name as an identifier.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325002272&siteId=291194637