This article will introduce you to the sentinel mode in Redis. I hope it will be helpful to you!
#Redis master-slave mode. Once the master node fails, the slave node can be promoted to the master node. At the same time, the client must be notified to update the master node address. This is generally not possible. OK. Therefore, Redis provides Redis Sentinel
Sentinel mechanism to solve this problem. [Related recommendations: Redis video tutorial]
psync
. If the synchronization fails at this time, full synchronization will be performed. While the main database performs full backup, millisecond or second-level lag may occur
node collection
Sentinel node will continuously monitor other
Sentinel Node and
Redis node send
PING, and confirm whether they are online by replying or not
does not receive a valid reply from the target node within
down-after-milliseconds milliseconds, the node will be determined to be subjectively offline.
node will pass
sentinel is-master-down-by- The addr command asks other
Sentinel nodes to determine the status of this node. If more than
nodes determine that the primary node is unreachable, the
Sentinel node will determine that the primary node is objectively offline.
Sentinel
sends to other Sentinel
nodes and Redis
master-slave nodes at a frequency of 1 times/s
PING
command. down-after-milliseconds
from the last valid reply to the PING
command, the instance is Sentinel
marked as Subjective offline . Sentinel
nodes of this masterserver are being monitored, 1 time/s
Confirm whether this master server has entered the subjective offline state<quorum></quorum>
nodes determine that the master node is unreachable, the Sentinel
node will It is determined that the master node is objectively offline. Sentinel
will send the INFO
command to all the servers of the offline server, which will start from 10 times/s
is changed to 1 times/s
. Sentinel
The nodes negotiate the master node status. If the master node is in the SDOWN
state, the new master node will be automatically selected by voting. Point the remaining slave nodes to the new primary node for data replication. Sentinel
to agree that the main server is offline, the objective offline status of the main server will be removed. When the primary server returns a valid reply
to the PING
command of Sentinel, the of the primary server The subjective offline status will be removed. Redis adopts the master-slave replication mode. Once the master node hangs up, the data being synchronized by the slave node may be lost and delayed. The bigger it is, the more is lost.
Redis provides two configuration items to limit the request processing of the main library, namely min-slaves-to-write
and min-slaves-max-lag
.
The requirement after combining these two configuration items is that there are at least N slave libraries in the slave library connected to the main library, and the ACK message delay when copying data with the main library cannot exceed T seconds, otherwise, the main library will no longer receive client requests.
So, Sentine cannot guarantee that messages will not be lost at all, but it can also try to ensure that messages are lost as little as possible.
Sentinel
solves the problem of high availability but does not solve the problem of single-node expansion of the master node.
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of Learn about the sentry mode in Redis in one article. For more information, please follow other related articles on the PHP Chinese website!