directory

  • What is a sentry
  • The principle of
  • The environment
  • Set the sentry
  • Recover from downtime and recovery
  • Master downtime and recovery
  • Configuring multiple sentries

1. What is a sentry

Sentinel is an independent process that monitors the operation of the Redis system. It has two functions:

  • Monitor whether the primary and secondary databases are running properly.
  • When the master data fails, the slave database will be automatically converted to the master database.

2, the principle of

Architecture of a single sentinel:

Multiple Sentinels architecture:

Multiple sentinels, not only monitoring master and slave databases simultaneously, but also monitoring each other.

Multiple sentries to prevent a single sentry failure.

3, environmental

Currently in a master and slave environment:

4. Set up sentries

To start the Sentry process, you first need to create the Sentry profile:

vim sentinel.conf
Copy the code

Input content:

Sentinel Monitor taotaoMaster 127.0.0.1 6379 1Copy the code

Description:

  • TaotaoMaster: The name used to monitor master data, which can be customized using upper and lower case letters and”. - _“Symbol
  • 127.0.0.1: IP address of the primary database to be monitored
  • 6379: Port of the monitored primary database
  • 1: minimum number of votes

Start the Sentry process:

redis-sentinel ./sentinel.conf
Copy the code

As can be seen from the figure above:

  • Sentry has begun that id is 9059917216012421 e8e89a4aa02f15b75346d2b7
  • A monitor was added for the Master database
  • 2 slaves found (it can be seen that the sentry does not need to configure the slave, just specify the master, the sentry will automatically discover the slave)

5. Recover from downtime

After killing process 2826, 30 seconds later sentry’s console output:

2989:X 05 Jun 20:09:33.509 # +sdown slave 127.0.0.1:6380 127.0.0.1 6380@taotaomaster 127.0.0.1 6379Copy the code

If we start the redis instance on port 3380, will it be automatically added to the master/slave replication?

2989:X 05 Jun 20:13:22.716 * +reboot slave 127.0.0.1:6380 127.0.0.1 6380@taotaomaster 127.0.0.1 6379 2989:X 05 Jun 20:13:22.788 # -sdown slave 127.0.0.1:6380 127.0.0.1 6380 @Taotaomaster 127.0.0.1 6379Copy the code

As you can see, slave is rejoined to the master slave replication. -sdown: indicates service recovery.

6. Master downtime and recovery

The Sentinel console printed the following message:

2989:X 05 Jun 20:16:50.300 # +sdown Master taotaoMaster 127.0.0.1 6379 +odown Master taotaoMaster 127.0.0.1 6379 # Quorum 1/1 2989:X 05 Jun 20:16:50.300 # +new-epoch 1 2989:X 05 Jun 20:16:50.300 # +try-failover Master taotaoMaster 127.0.0.1 6379 2989:X 05 Jun 20:16:50.304 # +vote-for-leader 9059917216012421 e8e89a4aa02f15b75346d2b7 1 vote sentry leader, 2989:X 05 Jun 20:16:50.304 # + elect-leader Master taotaoMaster 127.0.0.1 6379 Select Leader 2989:X 05 Jun 20:16:50.304 # +failover-state-select-slave master taotaoMaster 127.0.0.1 6379 Select one of the slave as master 2989:X 05 Jun 20:16:50.357 # +selected-slave slave 127.0.0.1:6381 127.0.0.1 6381 @ taotaoMaster 127.0.0.1 6379 Select 6381 2989:X 05 Jun 20:16:50.357 * +failover-state-send-slaveof-noone slave 127.0.0.1:6381 127.0.0.1 6381 @TAOtaomaster 127.0.0.1 6379 Run slaveof no one 2989:X 05 Jun 20:16:50.420 * + fail-state-wait-promotion slave 127.0.0.1:6381 127.0.0.1 6381 @ TaotaoMaster 127.0.0.1 6379 waiting for upgrade Master 2989:X 05 Jun 20:16:50.515 # + Promoted -slave slave 127.0.0.1:6381 127.0.0.1 6381 @Taotaomaster 127.0.0.1 6379 upgrade 6381 to Master 2989:X 05 Jun 20:16:50.515 # + Failover - state-reconf-Slaves Master TaotaoMaster 127.0.0.1 6379 2989:X 05 Jun 20:16:50.566 * +slave-reconf-sent slave 127.0.0.1:6380 127.0.0.1 6380@ TaotaoMaster 127.0.0.1 6379 2989:X 05 Jun 20:16:51.333 * +slave-reconf-inprog slave 127.0.0.1:6380 127.0.0.1 6380@ TaotaoMaster 127.0.0.1 6379 2989:X 05 Jun 20:16:52.382 * +slave-reconf-done slave 127.0.0.1:6380 127.0.0.1 6380@ TaotaoMaster 127.0.0.1 6379 2989:X 05 Jun 20:16:52.438 # + Failover -end Master taotaoMaster 127.0.0.1 6379 Failover completed 2989:X 05 Jun 20:16:52.438 # +switch-master taotaoMaster 127.0.0.1 6379 127.0.0.1 6381 master database changed from 6379 to 6381 2989:X 05 Jun 20:16:52.438 * +slave slave 127.0.0.1:6380 127.0.0.1 6380@taotaomaster 127.0.0.1 6381 Added 2989:X 05 Jun with 6380 as 6381 20:16:52.438 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ taotaoMaster 127.0.0.1 6381 Added slave 2989:X 05 Jun 6379 = 6381 20:17:22.463 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @TAOtaomaster 127.0.0.1 6381 Found that 6379 is down, waiting for the recovery of 6379Copy the code

So you can see that right now, 6,381 masters have one slave 6,380.

Next, let’s restore the status of 6379:

2989:X 05 Jun 20:35:32.172 # -sdown slave 127.0.0.1:6379 127.0.0.1 6379 @Taotaomaster 127.0.0.1 6381 6379 Service has been restored 2989:X 05 Jun 20:35:42.137 * +convert-to-slave slave 127.0.0.1:6379 127.0.0.1 6379 @Taotaomaster 127.0.0.1 6381 Set 6379 to slave of 6381Copy the code

7. Configure multiple sentries

vim sentinel.conf
Copy the code

Input content:

Sentinel Monitor taotaoMaster1 127.0.0.1 6381 1 Sentinel Monitor taotaoMaster2 127.0.0.1 6381 2Copy the code

Original link: blog.csdn.net/py_tamir/ar…

Copyright notice: This article is originally published BY CSDN blogger “Tamir_2017”. It is subject to CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement.

Recent hot articles recommended:

1.1,000+ Java Interview Questions and Answers (2021)

2. I finally got the IntelliJ IDEA activation code thanks to the open source project. How sweet!

3. Ali Mock is officially open source, killing all Mock tools on the market!

4.Spring Cloud 2020.0.0 is officially released, a new and disruptive version!

5. “Java Development Manual (Songshan version)” the latest release, quick download!

Feel good, don’t forget to click on + forward oh!