Redis sentinel mechanism and disaster drill

Time:2020-5-21

The Sentinels use this configuration

1. Modification sentinel.conf configuration file

Redis sentinel mechanism and disaster drill

2. Protected mode no

The    protected mode parameter is used to disable access to redis from the external network. If enabled, redis can only be accessed through lookback IP (127.0.0.1). If the external network accesses redis, an exception will be reported

Note:
If the bind parameter is disabled in the redis instance configuration file and the protected mode is set to no, the above error will still be reported when accessing redis from the Internet, because the protected mode no parameter needs to be added to the sentinel instance configuration file

Redis sentinel mechanism and disaster drill

3. Configure server configuration for monitoring

Redis sentinel mechanism and disaster drill

                                 Q

Quorum is explained as follows:

  (1) at least how many sentinels should agree that the master process is down, the slave process is down, or a failover operation should be started

  (2) quorum is used to identify faults. When a failover is actually performed, it is still necessary to elect a sentinel process in the sentinel cluster to perform the failover operation

  (3) suppose there are five sentinels, and quorum has set 2, then if two of the five sentinels think that the master is dead, one of the two sentinels will make an election, elect a sentinel to come out and perform the failover; if three of the five sentinels are running, the failover will be allowed to be performed

#Syntax: sentinel monitor < master name > < IP > < redis port > < quorum >
# Tells Sentinel to monitor this master, and to consider it in O_DOWN
# (Objectively Down) state only if at least <quorum> sentinels agree.
#Tell sentinel to monitor the master and consider it o_ DOWN 
#(only objectively o_ Down) status can only be approved by at least the number of sentinels in quorum.
# Note that whatever is the O_DOWN quorum, a Sentinel will require to
# be elected by the majority of the known Sentinels in order to
# start a failover, so no failover can be performed in minority.
#Note that regardless of the quorum number, sentinels need to do this by most known Sentinels
#Selected to initiate failover, so failover cannot be performed in a few cases.
# Replicas are auto-discovered, so you don't need to specify replicas in
# any way. Sentinel itself will rewrite this configuration file adding
# the replicas using additional configuration options.
#The slave is discovered automatically, so it does not need to be specified in any way. The sentry himself will override the profile to add
#To the configuration options for the profile used by the slave.
# Also note that the configuration file is rewritten when a
# replica is promoted to master.
#Note that the configuration file will be overwritten when the slave is specified as the host
# Note: master name should not include special characters or spaces.
# The valid charset is A-z 0-9 and the three characters ".-_".
#Note: host names should not contain special characters or spaces. The valid character set is A-Z 0-9 and three characters "." - ".
4. Other configurations

                         

                   (2), parallel syncs. After the new master is switched, how many slaves are switched to connect to the new master at the same time. The lower the number
Suppose your redis is one master and four slaves, and then the master is down. One of the four slaves is switched to the master, and the remaining three slaves will be hung on the new master. At this time, if parallel syncs is 1, then three slaves will be hung on the new master one by one, and one will be hung up, and the other will be hung up from the new master After syncing the data, hang the next one. If parallel syncs is 3, all slaves will be connected to the new master at one time

(3) failover timeout: timeout of failover

5. Set password permissions
# Set the password to use to authenticate with the master and replicas.
# Useful if there is a password set in the Redis instances to monitor.
#Set the password used for primary and secondary authentication.
#It is very useful if the password is set in the redis instance to be monitored
# Note that the master password is also used for replicas, so it is not
# possible to set a different password in masters and replicas instances
# if you want to be able to monitor these instances with Sentinel.
#Note that the master password is also used for the slave, so it is not possible for it to set different passwords in the host and slave instances
#If you want to use sentinels to monitor these instances.
# However you can have Redis instances without the authentication enabled
# mixed with Redis instances requiring the authentication (as long as the
# password set is the same for all the instances requiring the password) as
# the AUTH command will have no effect in Redis instances with authentication
# switched off.
#In addition, you can use redis instances without enabling authentication to mix with redis instances that need authentication (as long as
#For all instances requiring a password, the password set is the same in the redis instance using authentication), and the auth command will not work.
#Syntax: sentinel auth pass mymaster mysuper -- secret-0123passw0rd

Redis sentinel mechanism and disaster drill

  set to redis.conf Password configured in:

Redis sentinel mechanism and disaster drill

                     

6. Directly start the redis service of three servers

Redis sentinel mechanism and disaster drill

7. Check the log of redis service startup

Redis sentinel mechanism and disaster drill

   started successfully and connected to the host

8. Next, launch three sentries respectively, starting from the main engine

It can be seen from the figure below that the main engine is 172.16.178.2 and the slave is 172.16.178.3 and 172.16.178.4

Redis sentinel mechanism and disaster drill

9. Launch three sentinels: successful launch

Redis sentinel mechanism and disaster drill

10. View host’s sentinel.conf The configuration shows that the sentinel is monitoring two slaves and configured hosts, as well as two other sentinels

Redis sentinel mechanism and disaster drill

11. In the same way, the other two sentinels also monitor the two slaves and the configured hosts, as well as the other two sentinels

Redis sentinel mechanism and disaster drill

12. Connect the configured sentry

Redis sentinel mechanism and disaster drill

13. Enter info command

Redis sentinel mechanism and disaster drill

                    

14. Failure drill:

  1). Query the process ID of the host first

Redis sentinel mechanism and disaster drill

 2)、kill -9 70817

Redis sentinel mechanism and disaster drill

             the current node has only Sentinels

  3). Connect the current sentry and enter info

Redis sentinel mechanism and disaster drill

   this is the smallest sentinel configuration. If there is a master slave failover or a new sentinel process joins the sentinel cluster, the sentinel will automatically update its own configuration file

At this time, the host node becomes 172.16.178.4

  4), connect redis on 172.16.178.4

Redis sentinel mechanism and disaster drill

   the current node is the host node, and 172.16.178.3 is the slave node

  5). Restart redis on the 172.16.178.2 host

Redis sentinel mechanism and disaster drill

  6). Connect to the host again

Redis sentinel mechanism and disaster drill

  7). Host set a value

Redis sentinel mechanism and disaster drill

  8). The key set in the No.1 slave get host

Redis sentinel mechanism and disaster drill

  9). Key set in No.2 slave get host

Redis sentinel mechanism and disaster drill

Help to pay attention to WeChat official account study together: chengxuyuan95 (different programmer)Redis sentinel mechanism and disaster drill

Recommended Today

Python basics Chinese series tutorial · translation completed

Original: Python basics Python tutorial Protocol: CC by-nc-sa 4.0 Welcome anyone to participate and improve: a person can go very fast, but a group of people can go further. Online reading Apache CN learning resources catalog introduce Seven reasons to learn Python Why Python is great Learn Python introduction Executing Python scripts variable character string […]