Keepalived实战(3)

一、环境

如上图所示:

keepalived的mater为proxy-master,keepalived的slave为proxy-slave。

要求:当mater出现问题时,主动切换到slave上。这里只是进行简单的主从切换展示,后续会有专门一节将zabbix proxy高可用方式。

 

二、配置文件

1、master的配置文件

cat keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
xuequn@kingsoft.com
}
notification_email_from zabbix@kingsoft.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}

vrrp_script chk_zabbix_web {

script "killall -0 zabbix_proxy"
interval 10
weight 20

}


vrrp_instance VI_ZBX_WEB {
state BACKUP  #注意,这里因为考虑到切换成slave后我不再切回来,所以也配置成backup,且为nopreempt模式
nopreempt #when myself is master,set this option.
interface eth0
virtual_router_id 160
priority 100
advert_int 1
mcast_src_ip 192.168.1.102
authentication {
auth_type PASS
auth_pass ZabbixServer
}
track_script {

chk_zabbix_web

}
virtual_ipaddress {
192.168.1.100
}

#notify_master "/etc/keepalived/change_to_master.sh"
notify_backup "/etc/keepalived/change_to_backup.sh"   #切换为backup后,执行的脚本
}

 

slave上的配置:

cat keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
xuequn@kingsoft.com
}
notification_email_from zabbix@kingsoft.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}

 


vrrp_script chk_zabbix_web {

script "killall -0 zabbix_agentd"
interval 10
weight 20


}


vrrp_instance VI_ZBX_WEB {
state BACKUP
#nopreempt #when myself is master,set this option.
interface eth1
virtual_router_id 160
priority 90
advert_int 1
mcast_src_ip 192.168.1.101
authentication {
auth_type PASS
auth_pass ZabbixServer
}
track_script {

chk_zabbix_web

}
virtual_ipaddress {
192.168.1.100

}

notify_master "/etc/keepalived/change_to_master.sh"  #切换为master后,执行的脚本
#notify_backup "/etc/keepalived/change_to_backup.sh"
}

 

三、启动并测试

1、正常启动

2、故障切换

3、nopreempt测试

PS:本文纯属记录个人实践经历,如有问题,可随时联系我。QQ505711559

posted @ 2017-06-09 07:47  skyflask  阅读(551)  评论(0编辑  收藏  举报