Monday, October 17, 2016

Setup Redis Sentinel

Setup Redis Sentinel

Introduction

Redis Sentinel provides high availability for Redis, and handles any failover automatically without any need for human intervention. But it is also important to point out that the redis cluster also has an automated way of handling failover between masters and slaves. But sentinel adds an extra layer to guarantee high availability. Redis Sentinel also provides other collateral tasks such as monitoring, notifications and acts as a configuration provider for clients.

The installation of Sentinel demonstrated here assumes you installed Redis from the source tarball as demonstrated  here

Architecture

You can setup sentinel on the same servers as the master servers on the Redis cluster

Master servers

    redis-1-1
    redis-1-2
    redis-3-1

Slave servers

    redis-1-2
    redis-2-2
    redis-3-2 

Setup

Every redis instance comes with sentinel. To configure sentinel, edit the .../redis/sentinel.conf file and update/add the lined below. It is recommended to always use odd numbers for the number of sentinels instances to be running. And it is also advised to be running the sentinels instances on separate machines from the redis instances involved in the redis cluster (masters and slaves). Since our redis cluster has three masters and three slaves, i will setup three sentinel instances to monitor our three masters. It is not necessary to monitor the slaves since sentinel will auto-discover the slaves once their masters are configured. So lets go ahead and get started with our minimal config:

   port 26379
   daemonize yes
   loglevel notice
   syslog-enabled yes  
   #The 2 at the end of each line represents how many sentinel clusters have to
   #agree for a fail over to carry on
   sentinel monitor redis-1-1 ip_here 6379 2
   sentinel monitor redis-2-1 ip_here 6379 2
   sentinel monitor redis-3-1 ip_here 6379 2
  #allow to go down every 5 seconds
   sentinel down-after-milliseconds redis-1-1 50000
   sentinel down-after-milliseconds redis-2-1 50000
   sentinel down-after-milliseconds redis-3-1 50000
 
   sentinel failover-timeout redis-1-1 180000
   sentinel failover-timeout redis-2-1 180000
   sentinel failover-timeout redis-3-1 180000

   sentinel parallel-syncs redis-1-1 1
   sentinel parallel-syncs redis-2-1 1
   sentinel parallel-syncs redis-3-1 1

NOTE: Configure these parameters on all three redis master instances:

Start Sentinel

To start the sentinels, start them one by one, with 10 minutes apart from the previous run. This is because after the initial start, the other instances of sentinel with get the config of the first sentinel which might have changed depending on activities on the cluster.

To start a sentinel instance, run the following command:
    src/redis-sentinel ./sentinel.conf

If the redis server is not running on this instance of sentinel, then you can start sentinel together with the redis server with the following command:

   src/redis-server ./sentinel.conf --sentinel


No comments:

Post a Comment