📖 Scenario: You are managing a Redis database for a small online store. To ensure the database stays available even if the main Redis server fails, you want to set up Redis Sentinel. Sentinel monitors Redis servers and automatically switches to a backup if the main one goes down.
🎯 Goal: Set up a basic Redis Sentinel configuration to monitor a Redis master server and its replicas. This will help you understand how Sentinel works to keep your database available.
📋 What You'll Learn
Create a Redis master server configuration named redis-master with IP 192.168.1.100 and port 6379.
Create two Redis replica servers named redis-replica1 and redis-replica2 with IPs 192.168.1.101 and 192.168.1.102 respectively, both on port 6379.
Create a Sentinel configuration file that monitors the master server redis-master with quorum set to 2.
Add the final Sentinel configuration line to enable notification scripts.
💡 Why This Matters
🌍 Real World
Redis Sentinel is used in real-world systems to keep Redis databases available and automatically handle failover without manual intervention.
💼 Career
Understanding Sentinel configuration is important for roles like DevOps engineers, system administrators, and backend developers who manage reliable database systems.
Progress0 / 4 steps
1
Create Redis master and replica server configurations
Create three Redis server configuration entries as strings: redis_master with IP 192.168.1.100 and port 6379, redis_replica1 with IP 192.168.1.101 and port 6379, and redis_replica2 with IP 192.168.1.102 and port 6379.
Redis
Hint
Use simple string variables to store IP and port in the format 'IP:port'.
2
Create Sentinel monitoring configuration for the master
Create a variable called sentinel_monitor that contains the Sentinel configuration line to monitor the master server named redis-master at IP 192.168.1.100 and port 6379 with quorum set to 2. The format should be: sentinel monitor redis-master 192.168.1.100 6379 2.
Redis
Hint
Follow the exact format for the sentinel monitor command with the correct master name, IP, port, and quorum.
3
Add Sentinel configuration for down-after-milliseconds and failover timeout
Create two variables: down_after_milliseconds set to 'sentinel down-after-milliseconds redis-master 5000' and failover_timeout set to 'sentinel failover-timeout redis-master 10000' to configure Sentinel's timing settings for the master.
Redis
Hint
Use the exact strings for down-after-milliseconds and failover-timeout with the master name and values.
4
Add final Sentinel configuration to enable notification scripts
Create a variable called notification_script with the value 'sentinel notification-script redis-master /var/redis/notify.sh' to enable notification scripts for the master server.
Redis
Hint
Use the exact string to enable notification scripts for the master.
Practice
(1/5)
1. What is the main purpose of Redis Sentinel in a Redis setup?
easy
A. To compress Redis data for faster transmission
B. To store large amounts of data persistently
C. To monitor Redis servers and automatically handle failover
D. To provide a graphical user interface for Redis
Solution
Step 1: Understand Sentinel's role
Redis Sentinel monitors Redis servers to detect failures.
Step 2: Identify Sentinel's key feature
It automatically switches to a backup server if the main one fails, ensuring availability.
Final Answer:
To monitor Redis servers and automatically handle failover -> Option C
Quick Check:
Sentinel = automatic failover [OK]
Hint: Sentinel watches servers and switches on failure [OK]
Common Mistakes:
Confusing Sentinel with data storage
Thinking Sentinel provides UI
Assuming Sentinel compresses data
2. Which of the following is the correct way to start a Redis Sentinel instance using the command line?
easy
A. redis-sentinel /path/to/sentinel.conf
B. redis-server --sentinel /path/to/sentinel.conf
C. redis-cli sentinel start /path/to/sentinel.conf
D. redis-start sentinel /path/to/sentinel.conf
Solution
Step 1: Recall Redis Sentinel startup command
The correct command to start Sentinel is redis-sentinel followed by the config file.
Step 2: Check each option
redis-sentinel /path/to/sentinel.conf matches the correct syntax; others are invalid commands or flags.
Final Answer:
redis-sentinel /path/to/sentinel.conf -> Option A
Quick Check:
Sentinel starts with redis-sentinel command [OK]
Hint: Sentinel uses redis-sentinel command, not redis-server [OK]
Common Mistakes:
Using redis-server with --sentinel flag
Trying to start Sentinel via redis-cli
Using non-existent redis-start command
3. Given a Redis Sentinel setup monitoring a master named mymaster, what will the command redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster return?
medium
A. The configuration file path of Sentinel
B. The IP and port of the current master server
C. The list of all slaves under the master
D. An error because the command is invalid
Solution
Step 1: Understand the command purpose
The command queries Sentinel on port 26379 for the address of the master named 'mymaster'.
Step 2: Identify expected output
It returns the IP and port of the current master server Sentinel monitors.
Final Answer:
The IP and port of the current master server -> Option B
5. In a Redis Sentinel cluster with 5 Sentinel nodes monitoring 3 Redis masters, how many Sentinel nodes must agree to trigger a failover for a master if the quorum is set to 3?
hard
A. At least 2 Sentinel nodes must agree
B. Only 1 Sentinel node needs to agree
C. All 5 Sentinel nodes must agree
D. At least 3 Sentinel nodes must agree
Solution
Step 1: Understand quorum setting
The quorum setting defines the minimum number of Sentinels that must agree to start failover.
Step 2: Apply quorum to the cluster
With quorum set to 3, at least 3 Sentinel nodes must agree to trigger failover.
Final Answer:
At least 3 Sentinel nodes must agree -> Option D
Quick Check:
Quorum = minimum agreeing Sentinels [OK]
Hint: Quorum number = minimum Sentinels needed for failover [OK]
Common Mistakes:
Thinking only 1 Sentinel is enough
Assuming all Sentinels must agree
Confusing quorum with total Sentinel count
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.