一、准备
1.redis的主从准备
192.168.81.132(hadoop1) 主
192.168.81.130(hadoop2)从
2.heartbeat安装(主从都需要)
二、配置
1.Master配置
cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
cp
/usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/
cp
/usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
<1 vim /etc/ha.d/ha.cf
debugfile /var/log/ha-debug --debug日志
logfile
/var/log/ha-log --日志
logfacility
local0 --日志设备
keepalive 2 --心跳时间
deadtime
30 --心跳死亡时间,也就是说多少秒收不到心跳认为死亡
warntime
10 --收不到心跳后多少秒,会在日志里写入一个警告,必须小于deadtime
initdead 120
udpport
694 --端口
ucast eth0 192.168.81.130
auto_failback
on --slave接管了服务,master重新启动后,会自动再次接管服务成为master
node
hadoop1
node hadoop2 --master和slave的主机名
ping_group
group1 192.168.81.1 192.168.81.130
respawn hacluster
/usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
<2.vim /etc/ha.d/authkeys
auth 1 --表示使用第一种认证方式
1 crc
chmod 600 /etc/ha.d/authkeys
<3.vim /etc/ha.d/haresources
hadoop1 IPaddr::192.168.81.100/24/eth0:0 redisd
2.slave配置
scp /etc/ha.d/ha.cf hadoop2:/etc/ha.d/
scp /etc/ha.d/authkeys
hadoop2:/etc/ha.d/
scp /etc/ha.d/haresources hadoop2:/etc/ha.d/
<1.vim /etc/ha.d/ha.cf
ucast eth0 192.168.81.130
chmod 600 /etc/ha.d/authkeys
三、测试
1.主从都启动 /etc/init.d/heartbeat start
2.查看是否获取到浮动IP eth0:0 192.168.81.100
3.将主的网络停止,测试slave是否接管
4., 手工进行资源的切换
#/usr/lib/heartbeat/hb_standby
--手工把资源让给另一台
#/usr/lib/heartbeat/hb_takeover --手工把资源从另一台抢过来
四、备注
vim /etc/ha.d/haresources
hadoop1 IPaddr::192.168.81.100/24/eth0:0 redisd
redisd脚本自定义如下:
#!/bin/sh #chkconfig: 345 86 14 #description: Startup and shutdown script for Redis PROGDIR=/home/hadoop/source/redis-2.8.7/src PROGNAME=redis-server DAEMON=$PROGDIR/$PROGNAME CONFIG=/home/hadoop/source/redis-2.8.7/redis.conf PIDFILE=/var/run/redis.pid DESC="redis daemon" SCRIPTNAME=/etc/init.d/redisd start() { if test -x $DAEMON then echo -e "Starting $DESC: $PROGNAME" if $DAEMON $CONFIG then echo -e "OK" else echo -e "failed" fi else echo -e "Couldn‘t find Redis Server ($DAEMON)" fi } stop() { if test -e $PIDFILE then echo -e "Stopping $DESC: $PROGNAME" if kill `cat $PIDFILE` then echo -e "OK" else echo -e "failed" fi else echo -e "No Redis Server ($DAEMON) running" fi } restart() { echo -e "Restarting $DESC: $PROGNAME" stop start } list() { ps aux | grep $PROGNAME } case $1 in start) start ;; stop) stop ;; restart) restart ;; list) list ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2 exit 1 ;; esac exit 0
redis.conf的bind 注释
应用系统链接地址为
protected static RedisClient Redis_Write = new RedisClient("192.168.81.100", 6379);//redis服务IP和端口
采用heartbeat做Redis的主从切换,布布扣,bubuko.com
原文:http://www.cnblogs.com/bobsoft/p/3650115.html