Running Redis with Sentinel for High Availability on Linux
Launching Redis with Sentinel on Linux
Redis is a popular in‑memory data store used for caching and improving application performance. To maintain uptime and automatically handle failures, the Sentinel system provides monitoring, notification, and automatic failover for Redis instances. This article explains how to configure and start Redis together with Sentinel on a Linux system.
What Is Sentinel?
Sentinel is a distributed system that watches over your Redis master and replicas. It detects when the master goes down, elects a new master from the available replicas, and reconfigures the other replicas to follow the new master. This process ensures the Redis service remains available without manual intervention.
Setting Up Redis and Sentinel
1. Install Redis
Use your distribution’s package manager. For Debian/Ubuntu systems:
sudo apt update
sudo apt install redis-server
2. Configure the Redis Master and Replicas
Edit the Redis configuration file (typically /etc/redis/redis.conf). For a replica instance, add the line pointing to the master:
replicaof 192.168.1.100 6379
Replace the IP and port with your actual master details.
3. Prepare a Sentinel Configuration
Create a dedicated Sentinel config file (e.g., /etc/redis/sentinel.conf) with atleast the following:
sentinel monitor mymaster 192.168.1.100 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
Here mymaster is a logical name, 192.168.1.100 and 6379 point to the master, and 2 is the quorum (number of sentinels that must agree the master is down).
4. Start the Redis Instances
First launch the master and then any replicas (make sure the replica config includes the replicaof directive). Use:
redis-server /path/to/redis.conf
To start the Sentinel process, run:
redis-server /path/to/sentinel.conf --sentinel
Or alternatively:
redis-sentinel /path/to/sentinel.conf
5. Verify Sentinel Operation
Connect to the Sentinel port (default 26379) and check its state:
redis-cli -p 26379
SENTINEL masters
You should see details about the monitored master and its replicas.
Automation with a Shell Script
Below is a simple script that starts Redis and Sentinel in the correct order:
#!/bin/bash
MASTER_CFG="/etc/redis/redis-master.conf"
SENTINEL_CFG="/etc/redis/sentinel.conf"
echo "Starting Redis master..."
redis-server "$MASTER_CFG"
echo "Starting Redis Sentinel..."
redis-sentinel "$SENTINEL_CFG"
Make the script executable and run it.
Important Considerations
- Run at least three Sentinel instances to avoid a split‑brain scenario.
- Sentinel itself does not require authentication by default; secure it with
requirepassandsentinel auth-passwhen needed. - Always test failover behaviour in a non‑production environment first.
By following these steps you can build a resilient Redis deployment on Linux that automatically recovers from master failures using Sentinel.