Setup Redis Sentinel High Availability on VPS
Redis Sentinel is a high availability system for Redis that monitors the status of master and slave nodes. When a master goes down, Sentinel automatically selects the best slave to become the new master. Applications connecting through Sentinel experience zero downtime. This makes it ideal for production systems that use Redis as a session store or job queue.
Redis Sentinel Architecture
You need at least 3 nodes to achieve proper quorum for failover decisions:
- Node 1: Redis Master (handles writes)
- Node 2: Redis Slave + Sentinel
- Node 3: Redis Slave + Sentinel (or run 3 Sentinel processes on a single VPS if needed)
Install Redis on All Nodes
sudo apt update
sudo apt install redis-server -y
# Check version
redis-cli --version
redis-server --version
Configure Redis Master
sudo nano /etc/redis/redis.conf
# Bind to all interfaces (use firewall to control access)
bind 0.0.0.0
# Set password (requirepass)
requirepass YourStrongRedisPassword
# No need to set replicaof for master
sudo systemctl restart redis-server
Configure Redis Slave
sudo nano /etc/redis/redis.conf
bind 0.0.0.0
requirepass YourStrongRedisPassword
# Point to master
replicaof MASTER-IP 6379
masterauth YourStrongRedisPassword
# Slave is read-only
replica-read-only yes
sudo systemctl restart redis-server
Configure Redis Sentinel
sudo nano /etc/redis/sentinel.conf
port 26379
daemonize yes
logfile /var/log/redis/sentinel.log
pidfile /var/run/redis/redis-sentinel.pid
# Monitor master named "mymaster"
sentinel monitor mymaster MASTER-IP 6379 2
# quorum = 2 means at least 2 Sentinels must agree
sentinel auth-pass mymaster YourStrongRedisPassword
# Failover after master is unresponsive for 5 seconds
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
sudo redis-sentinel /etc/redis/sentinel.conf
# Or run as a service
sudo systemctl enable --now redis-sentinel
Verify Redis Sentinel is Working Correctly
# Check replication status from master
redis-cli -a YourStrongRedisPassword info replication
# Check Sentinel status
redis-cli -p 26379 sentinel masters
redis-cli -p 26379 sentinel slaves mymaster
# View Sentinel log
sudo tail -f /var/log/redis/sentinel.log
# Test failover (stop master and watch slave take over)
sudo systemctl stop redis-server # on master node
# Wait 10 seconds then check from slave
redis-cli -a YourStrongRedisPassword info replication
info replication output, look for the line role:master or role:slave to confirm the node's current role.
Common Issues & Troubleshooting
Slave Not Syncing with Master (repl-backlog Full)
Increase the replication buffer in the master's redis.conf:
sudo nano /etc/redis/redis.conf
repl-backlog-size 64mb
client-output-buffer-limit replica 256mb 64mb 60
sudo systemctl restart redis-server
Sentinel Not Performing Failover (Quorum Not Met)
Check that all Sentinels can reach each other:
# Verify all Sentinels see each other
redis-cli -p 26379 sentinel sentinels mymaster
# All Sentinels should appear in the list
# Check firewall allows port 26379
sudo ufw allow from OTHER-SENTINEL-IP to any port 26379
Application Cannot Connect After Failover
Your application must use a Sentinel-aware client library, not direct Redis connections:
# PHP (Predis)
$sentinels = [
['127.0.0.1', 26379],
['NODE2-IP', 26379],
];
$client = new Predis\Client($sentinels, ['replication' => 'sentinel', 'service' => 'mymaster']);
# Python (redis-py)
from redis.sentinel import Sentinel
sentinel = Sentinel([('127.0.0.1', 26379), ('NODE2-IP', 26379)])
master = sentinel.master_for('mymaster', password='YourPassword')
Error: "NOAUTH Authentication required"
You forgot to set masterauth in the slave config:
sudo nano /etc/redis/redis.conf
masterauth YourStrongRedisPassword
sudo systemctl restart redis-server
Frequently Asked Questions
What's the difference between Redis Sentinel and Redis Cluster?
Redis Sentinel provides high availability by automatically switching the master, but data still lives on a single node. Redis Cluster does horizontal sharding, distributing data across multiple shards with built-in HA. Use Cluster for datasets larger than a single node's RAM. Sentinel is better when you need HA without sharding.
How many VPS instances do I need for Redis Sentinel?
At least 3 nodes to form a proper quorum. With only 2 Sentinels, failover cannot occur because quorum is not met. If budget is tight, you can run 3 Sentinel processes on 2 VPS instances, but this is not recommended for production environments.
Can Redis Sentinel send notifications when failover occurs?
Yes, through the sentinel notification-script configured in sentinel.conf. Sentinel calls your script when sdown or odown events occur, passing event type and master name as arguments. Your script can then send alerts through email, webhooks, or other channels.