While I know how to configure and run Redis master and slave on two different servers, I would like to whether my Webserver will be able to connect to slave redis server if the master redis server goes down?

If that is not the case, May I know how can I achieve that?



  • Balajidl, you should consider marking answers as the accepted answer on your other questions. If there are no good answers, consider restating the questions or closing the question on your own. – gWaldo Aug 21 '12 at 15:39

At the server side, for a simple failover, you can do it by using Nagios and NRPE.

On the Nagios server:

define service{
    use                     critical-service
    host_name               B
    service_description     redis:2302
    check_command           check_tcp!2302
    event_handler           promote_redis!C!2302
    contact_groups          admin-sms,admin


define command{ 
    command_name    promote_redis
    command_line    $USER1$/eventhandlers/promote_redis.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$ $ARG1$ $ARG2$



case "$1" in
        /usr/local/nagios/libexec/check_nrpe -H $4 -c promote_redis -a $5
        /usr/local/nagios/libexec/check_nrpe -H $4 -c promote_redis -a $5

exit 0

On the slave:


command[promote_slave_redis]=/usr/lib64/nagios/plugins/promote_redis.sh $ARG1$



echo 'slaveof no one' | /usr/local/redis/bin/redis-cli -h C -p $1

Virtual IP can be set up by using keepalived, something like this:


vrrp_script chk_redis {
    script "killall -0 redis-server"
    interval 2
    weight 2

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    lvs_sync_daemon_interface eth0
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass pa$$w0rd
    virtual_ipaddress {
    track_script {

But what happens if you want to run multiple instances?

Yves Trudeau and Percona wrote a great resource agent to failover MySQL. Based on that, Martin Walter rewrite for the Redis service. Give it a try!

crm configure show

node master_629
node svr200-632.localdomain
primitive VIP ocf:heartbeat:IPaddr2 \
    params ip="" cidr_netmask="24" \
    meta target-role="Started"
primitive redis_6380 ocf:heartbeat:redis \
    params config="/usr/local/redis/etc/redis.conf"
ms ms_redis_6380 redis_6380 \
    meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" target-role="Started"
location REDIS-PREFER-master_629 ms_redis_12345 100: master_629
colocation vip_on_ms_redis_6380 inf: VIP:Started ms_redis_6380:Master
order vip_after_ms_redis_6380 inf: ms_redis_6380:promote VIP:start
property $id="cib-bootstrap-options" \
    no-quorum-policy="ignore" \
    default-action-timeout="60s" \
    stonith-enabled="false" \
    startup-fencing="false" \
    dc-version="1.0.12-unknown" \
    cluster-infrastructure="openais" \

crm status

Last updated: Tue Aug 21 22:12:11 2012
Stack: openais
Current DC: master_629 - partition with quorum
Version: 1.0.12-unknown
2 Nodes configured, 2 expected votes
6 Resources configured.

Online: [ svr200-632.localdomain master_629 ]

 Master/Slave Set: ms_redis_12345
     Masters: [ master_629 ]
     Slaves: [ svr200-632.localdomain ]
 VIP    (ocf::heartbeat:IPaddr2):   Started master_629
 Master/Slave Set: ms_redis_6380
     Masters: [ master_629 ]
     Slaves: [ svr200-632.localdomain ]
  • i like this.. also a great solution – Mike Aug 21 '12 at 16:03
  • You are mentioning ms_redis_12345 in crm config. Is this a typo? Should it be ms_redis_6380 instead? – Goran Jurić Sep 5 '13 at 11:34

You either handle it in the client or use something like


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.