High Availability
Redis Sentinel-Based High Availability¶
Topology¶
- Prerequisite
- At least three Redis instances (master and two replicas).
-
Three Sentinel instances (can be colocated with Redis or separate).
-
Install Redis
- Install Redis on all nodes. Use your package manager (
apt
,yum
, orbrew
) or compile from source. -
Example (Ubuntu):
1 2
sudo apt update sudo apt install redis-server
-
Configure Redis Nodes
- Set up one master and two or more replicas.
- In the configuration file (
/etc/redis/redis.conf
), configure:bind
: Specify the IP to bind (e.g.,bind 0.0.0.0
for all interfaces).protected-mode no
(if remote access is required).- Enable persistence (
appendonly yes
).
-
Configure replicas to point to the master:
1
replicaof <master_ip> <master_port>
-
Start Redis Instances
-
Start Redis on all nodes and ensure the replicas sync with the master by performing some of the TESTING STEPS.
-
Install and Configure Sentinel
- On each Sentinel node, configure the
sentinel.conf
file:1 2 3 4 5
sentinel monitor mymaster <master_ip> <master_port> 2 sentinel auth-pass mymaster <password> # If password-protected sentinel down-after-milliseconds mymaster 5000 sentinel parallel-syncs mymaster 1 sentinel failover-timeout mymaster 10000
-
Replace
<master_ip>
and<master_port>
with the master node’s details. -
Start Sentinel Instances
- Run Redis Sentinel using the command:
1
redis-server /path/to/sentinel.conf --sentinel
-
Verify that the Sentinels monitor the master and replicas.
-
Test Failover
- Stop the master Redis instance.
- Ensure a Sentinel promotes one of the replicas to master.
- Test client applications for automatic failover (update connection logic to handle Sentinel or use HAProxy).