Skip to content

High Availability

Redis Sentinel-Based High Availability

Topology

  1. Prerequisite
  2. At least three Redis instances (master and two replicas).
  3. Three Sentinel instances (can be colocated with Redis or separate).

  4. Install Redis

  5. Install Redis on all nodes. Use your package manager (apt, yum, or brew) or compile from source.
  6. Example (Ubuntu):

    1
    2
    sudo apt update
    sudo apt install redis-server
    

  7. Configure Redis Nodes

  8. Set up one master and two or more replicas.
  9. 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).
  10. Configure replicas to point to the master:

    1
    replicaof <master_ip> <master_port>
    

  11. Start Redis Instances

  12. Start Redis on all nodes and ensure the replicas sync with the master by performing some of the TESTING STEPS.

  13. Install and Configure Sentinel

  14. 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
    
  15. Replace <master_ip> and <master_port> with the master node’s details.

  16. Start Sentinel Instances

  17. Run Redis Sentinel using the command:
    1
    redis-server /path/to/sentinel.conf --sentinel
    
  18. Verify that the Sentinels monitor the master and replicas.

  19. Test Failover

  20. Stop the master Redis instance.
  21. Ensure a Sentinel promotes one of the replicas to master.
  22. Test client applications for automatic failover (update connection logic to handle Sentinel or use HAProxy).