Mastering Redis Sentinel: Setup, Failover, and Multi‑Sentinel Configuration
This guide explains what Redis Sentinel is, its architecture, how to configure it in a master‑replica environment, and demonstrates handling both slave and master failures with detailed log examples, plus tips for running multiple Sentinel instances for high availability.
What Is Redis Sentinel?
Sentinel monitors the health of a Redis deployment. It runs as an independent process and provides two functions:
Monitor whether the master and replica instances are running correctly.
Automatically promote a replica to master when the master fails.
Architecture
Single‑sentinel architecture:
Multiple‑sentinel architecture (sentinels monitor each other):
Test Environment
Example one‑master‑multiple‑replica setup:
Configuring a Sentinel
Create a Sentinel configuration file: vim sentinel.conf Add a monitor line: sentinel monitor taotaoMaster 127.0.0.1 6379 1 Parameters:
taotaoMaster : name of the master to monitor (customizable, may contain letters, digits, “.-_”).
127.0.0.1 : IP address of the master.
6379 : port of the master.
1 : quorum (minimum number of votes required to consider the master down).
Start the Sentinel process: redis-sentinel ./sentinel.conf Console output shows that Sentinel started (ID 9059917216012421e8e89a4aa02f15b75346d2b7), added a monitor for the master, discovered two replicas, and began monitoring them.
Slave Crash and Recovery
After killing the slave process (port 6380), Sentinel logs:
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 6379When the slave is restarted, Sentinel logs:
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 6379The slave re‑joins the replication group, and the “-sdown” entry indicates service recovery.
Master Crash and Recovery
When the master (port 6379) goes down, Sentinel logs a series of events leading to failover:
2989:X 05 Jun 20:16:50.300 # +sdown master taotaoMaster 127.0.0.1 6379 # master down
2989:X 05 Jun 20:16:50.300 # +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 9059917216012421e8e89a4aa02f15b75346d2b7 1
2989:X 05 Jun 20:16:50.304 # +elected-leader master taotaoMaster 127.0.0.1 6379
2989:X 05 Jun 20:16:50.304 # +failover-state-select-slave master taotaoMaster 127.0.0.1 6379
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
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
2989:X 05 Jun 20:16:50.420 * +failover-state-wait-promotion slave 127.0.0.1:6381 127.0.0.1 6381 @ taotaoMaster 127.0.0.1 6379
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
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
2989:X 05 Jun 20:16:52.438 # +switch-master taotaoMaster 127.0.0.1 6379 127.0.0.1 6381 # new master
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
2989:X 05 Jun 20:16:52.438 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ taotaoMaster 127.0.0.1 6381After the failover, port 6381 becomes the new master with 6380 as its replica. When the original master (6379) comes back online, Sentinel logs:
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
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 6381Thus the recovered instance is added as a replica of the new master.
Configuring Multiple Sentinels
To run several Sentinel instances, add multiple monitor lines to the same configuration file:
sentinel monitor taotaoMaster1 127.0.0.1 6381 1
sentinel monitor taotaoMaster2 127.0.0.1 6381 2Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
