0
0
Redisquery~30 mins

Automatic failover in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Automatic Failover Setup in Redis
📖 Scenario: You are managing a Redis database for a small online store. To ensure the store stays online even if the main Redis server fails, you want to set up automatic failover using Redis Sentinel.
🎯 Goal: Set up a Redis Sentinel configuration that monitors a Redis master server and automatically promotes a replica to master if the master fails.
📋 What You'll Learn
Create a Redis master configuration with a specific name.
Create at least two Redis replica configurations.
Configure Redis Sentinel to monitor the master with a quorum of 2.
Set the failover timeout to 10000 milliseconds.
💡 Why This Matters
🌍 Real World
Automatic failover ensures that if the main Redis server crashes, a replica takes over immediately, keeping applications running smoothly without manual intervention.
💼 Career
Understanding Redis Sentinel and failover is important for roles like DevOps engineers, backend developers, and system administrators who maintain reliable and scalable database systems.
Progress0 / 4 steps
1
Create Redis master configuration
Create a Redis master configuration file named redis-master.conf with the following settings: set port 6379 and daemonize yes.
Redis
Need a hint?

Use port 6379 to set the port and daemonize yes to run Redis in the background.

2
Create Redis replica configurations
Create two Redis replica configuration files named redis-replica1.conf and redis-replica2.conf. Each should have port 6380 and port 6381 respectively, daemonize yes, and set replicaof 127.0.0.1 6379 to replicate the master.
Redis
Need a hint?

Each replica must have its own port and replicate the master at 127.0.0.1 port 6379.

3
Configure Redis Sentinel to monitor the master
Create a Redis Sentinel configuration file named sentinel.conf. Add the line sentinel monitor mymaster 127.0.0.1 6379 2 to monitor the master named mymaster at IP 127.0.0.1 port 6379 with a quorum of 2. Also add sentinel down-after-milliseconds mymaster 5000 and sentinel failover-timeout mymaster 10000.
Redis
Need a hint?

The sentinel monitor line tells Sentinel what master to watch and the quorum needed. The other lines set timing for failover.

4
Complete Sentinel configuration with notification script
In sentinel.conf, add the line sentinel notification-script mymaster /usr/local/bin/notify.sh to specify a notification script that runs on failover events.
Redis
Need a hint?

This line tells Sentinel to run a script when failover events happen, useful for alerts.