Sentinel Installation for Redis HA

After setting up a Redis master-slave replication as shown here, you will need a solution to manage fail overs just incase the master goes down and need to promote a slave automatically.

For the post, i am assuming that your architecture included one redis master with two slaves configured. Otherwise if you have only one master with one slave, then “sentinel monitor my master…” line to 1 in the config file below.

Redis Sentinel is a well design tool to do just that.

On each server, install sentinel:

sudo apt-get install redis-sentinel

On all three servers, make a backup of the sentinel configuration files /etc/redis/sentinel.conf and create new ones with the following config:

bind 0.0.0.0
daemonize yes
dir "/var/lib/redis"
loglevel notice
logfile "/var/log/redis/redis-sentinel.log"
pidfile "/var/run/redis/redis-sentinel.pid"
port 26379
syslog-enabled yes
sentinel monitor mymaster master_ip_address 6379 2
#sentinel auth-pass mymaster redis_password
sentinel down-after-milliseconds mymaster 10000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster 1
maxclients 4064

*NOTE: The line “sentinel monitor my master …” should be configured first before other “sentinel” config including the master’s name (my master in this case).

Restart Sentinel on each serever:

sudo service redis-sentinel restart

Sentinel will self discover the slaves, and will dynamically changes its config file appropriately depending on activities on the redis servers, including handling failures.

CONCLUSION

To understand more of the config in sentinel, you can access the original sentinel.con file that we backed up and read the details there. I like to create a new config file to make the file readable and easy to maintain.

 

 

Leave a comment