用keepalived作HA(结合haproxy)真是爽呆了,漂移速度非常快,下面是编译安装配置过程
- #wget http://www.keepalived.org/software/keepalived-1.2.2.tar.gz
- #cd keepalived-1.2.2
- #./configure
- # make && make install && make clean
稍作配置
- #cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
- #cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
- #mkdir /etc/keepalived
- #cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
- #cp /usr/local/sbin/keepalived /usr/sbin/
修改keepalived.conf
以下是master上的
- ! Configuration File for keepalived
- #全局定义
- global_defs {
- notification_email { # 邮件通知
- xxx@gmail.com #邮件地址
- }
- notification_email_from xxx@163.com #发件人地址
- smtp_server smtp.163.com #smtp server
- smtp_connect_timeout 5 #smtp 超时时间
- router_id LVS_DEVEL
- }
- vrrp_script chk_haproxy {
- script "killall -0 haproxy"
- interval 2
- weight 2
- }
- vrrp_instance VI_1 { #实列名-可以自定义
- state MASTER #角色
- interface eth0 #HA检测的设备
- virtual_router_id 50 #虚拟路由ID一组集群必须设置为同一个ID,tcpdump vrrp可获得
- priority 200 #权重,backup不能高于master
- advert_init 1 #检测时间间隔
- smtp_alert #开启smtp通知
- garp_master_delay 1 #主从切换时间,单位为秒。
- mcast_src_ip xxx.xxx.xxx.xxx #master主机地址
- authentication { #认证设置
- auth_type PASS #认证类型
- auth_pass $RFV7ygv #认证密码,设置为一致
- }
- track_interface {
- eth0
- eth1
- }
- virtual_ipaddress { #虚拟IP定义,可以多个
- xxx.xxx.xxx.xxx #vip定义
- }
- track_script {
chk_haproxy #HA检测的定义
}
}
backup上的keepalived
- ! Configuration File for keepalived
- global_defs {
- notification_email {
- xxx@126.com
- }
- notification_email_from xxx@163.com
- smtp_server smtp.163.com
- smtp_connect_timeout 5
- router_id LVS_DEVEL
- }
- vrrp_script chk_haproxy {
- script "killall -0 haproxy"
- interval 2
- weight 2
- }
- vrrp_instance VI_1 {
- state BACKUP #角色
- interface eth0
- virtual_router_id 50 #与master保持一致
- priority 100 #权重低于master
- advert_init 1
- smtp_alert
- garp_master_delay 1
- mcast_src_ip xxx.xxx.xxx.xxx #backup主机地址
- authentication {
- auth_type PASS
- auth_pass $RFV7ygv
- }
- track_interface {
- eth0
- eth1
- }
- virtual_ipaddress {
- xxx.xxx.xxx.xxx #vip address
- }
- track_script {
chk_haproxy
}
}
PS:
配置完keepalived文件后 ,简单测试一下哈 ^_^
把master主机网卡停止, 可以瞬间切换到backup主机
启动master主机的网卡 master又抢占回vip
在业务应用十分频繁的系统上,如果master发生故障,切换回backup,master主机online后,又切换回到master,如此频繁的切换是无法容忍的,可以设置不抢占的方法
具体方法是将master主机的state也设置为BACKUP,在state BACKUP下面加入nopreempt
backup主机不需要加入,两个主机根据priority的高低进行抢占,高的为MASTER主机
本文转自dongfang_09859 51CTO博客,原文链接:http://blog.51cto.com/hellosa/530619,如需转载请自行联系原作者