Introduction
Redis Sentinel ensures high availability of Redis by monitoring instances, managing automatic failovers, and notifying administrators. In a production context, it becomes essential to avoid service interruptions. This tutorial covers a master-replica architecture with three sentinels for fault tolerance. You will learn how to deploy, configure, and monitor Sentinel robustly.
Prerequisites
- Redis 7.2+ installed on three servers
- Root or sudo access on the machines
- Advanced knowledge of Linux and networking
- Docker (optional for testing)
- Monitoring tools such as Prometheus
Master Redis Configuration
bind 0.0.0.0
port 6379
protected-mode no
appendonly yes
appendfsync everysec
This file configures the master Redis instance to accept connections and enable AOF persistence. Protected-mode is disabled only for the controlled environment.
Replica Configuration
bind 0.0.0.0
port 6379
protected-mode no
replicaof 192.168.1.10 6379
appendonly yes
Each replica points to the master via replicaof. This configuration ensures real-time replication and high availability.
Sentinel Configuration File
port 26379
sentinel monitor mymaster 192.168.1.10 6379 2
sentinel down-after-milliseconds mymaster 5000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 10000
This file sets the quorum to 2 sentinels, detection delays, and failover timeouts. Adjust IPs according to your network.
Sentinel Startup Script
#!/bin/bash
redis-sentinel /etc/redis/sentinel.conf --sentinel
Simple script to launch Sentinel as a service. Make it executable with chmod +x and integrate it into systemd.
Systemd Configuration for Sentinel
[Unit]
Description=Redis Sentinel
After=network.target
[Service]
ExecStart=/usr/bin/redis-sentinel /etc/redis/sentinel.conf
Restart=always
[Install]
WantedBy=multi-user.target
This systemd service ensures Sentinel restarts automatically after a crash or server reboot.
Best Practices
- Deploy at least three sentinels on separate machines
- Use fixed IP addresses and internal DNS
- Regularly test failovers in a staging environment
- Enable authentication with Redis 6+ ACLs
- Monitor metrics via Prometheus exporter
Common Mistakes to Avoid
- Forgetting to synchronize NTP clocks between nodes
- Setting a quorum too high, making the cluster unavailable
- Neglecting firewall rules for port 26379
- Failing to test automatic failover before going live
Further Reading
Deepen your skills with our advanced training on high availability and system resilience. Discover our Learni courses.