Redis Master and Slave usage
Solution 1:
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$
}
promote_redis.sh
#!/bin/bash
case "$1" in
OK)
;;
WARNING)
;;
UNKNOWN)
/usr/local/nagios/libexec/check_nrpe -H $4 -c promote_redis -a $5
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H $4 -c promote_redis -a $5
;;
esac
exit 0
On the slave:
nrpe.cfg
command[promote_slave_redis]=/usr/lib64/nagios/plugins/promote_redis.sh $ARG1$
promote_redis.sh
#!/bin/bash
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:
/etc/keepalived/keepalived.conf
vrrp_script chk_redis {
script "killall -0 redis-server"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
#nopreempt
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 {
x.y.z.t
}
track_script {
chk_redis
}
}
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="192.168.6.179" 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" \
expected-quorum-votes="2"
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 ]
Solution 2:
You either handle it in the client or use something like
https://github.com/sreeix/redis-proxy