1.下载:
wget http://www.keepalived.org/software/keepalived-1.2.15.tar.gz
2.解压安装:
yum install ipvsadm
tar -zxvf keepalived-1.2.15.tar.gz
cd keepalived-1.2.15
./configure --prefix=/usr/local/keepalived-1.2.15 --disable-fwmark
make && make install
cd /usr/local;
ln -s keepalived-1.2.15 keepalived
3.配置:
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
chmod +x /etc/init.d/keepalived
mkdir -p /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig
cp /usr/local/keepalived/sbin/keepalived /sbin
echo ‘export PATH=/usr/local/keepalived/sbin:$PATH;‘ >/etc/profile.d/keepalived.sh
chmod u+x /etc/profile.d/keepalived.sh
具体keepalived配置文件如下:
-----------------------------------------
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
#设置原主机恢复正常时,服务不漂移;
nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.16.77
}
}
----------------------------------------
SLAVER上与MASTER上大致相同,改下这两个就可以了 state BACKUP
priority 80
4.keepalive自定义监控功能说明:
notify_master keepalived切换到master时执行的脚本
notify_backup keepalived切换到backup时执行的脚本
notify_fault keepalived出现故障时执行的脚本
vrrp_script代码块是用来定义监控脚本,脚本执行时间间隔以及脚本的执行结果导致优先级变更幅度的。
vrrp_script chk_redis {
script "/etc/keepalived/scripts/redis_check.sh" #指定执行脚本的路径
interval 1 #指定脚本的执行时间间隔
weight 10 #脚本结果导致的优先级变更:10表示优先级+10;-10则表示优先级-10
}
定义好vrrp_script代码块之后,就可以在instance中使用了
track_script {
chk_redis
}
注意:VRRP脚本(vrrp_script)和VRRP实例(vrrp_instance)属于同一个级别
http://my.oschina.net/guol/blog/182491
本文出自 “webseven” 博客,请务必保留此出处http://webseven.blog.51cto.com/4388012/1649879
原文:http://webseven.blog.51cto.com/4388012/1649879