MASTER
vim /etc/keepalived/keepalived.conf
global_defs {
router_id LVS_KEEP01 #主备上要不同的名称
}
vrrp_script check_nginx { #定义监控nginx的脚本(脚本需要执行权限)
script “/script/check_nginx.sh”
interval 2 #检查间隔时间
weight -51 #失败时优先级的变化 priority值 + weight值 = 新优先级值
fall 2 #失败几次后真正确认为失败
rise 1 #成功几次后确认为成功
}
vrrp_instance VI_1 { #主备名称要相同
state MASTER #主是MASTER备是BACKUP
interface eth0
lvs_sync_daemon_inteface eth0 #同步接口虚拟机可不写
virtual_router_id 51 #Id主备名称要相同
priority 150 #优先级越大表示优先
advert_int 1 #心跳检查单位秒
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #VIP
10.125.192.100/24
}
track_script { #执行监控nginx进程的脚本
check_nginx
}
}
BACKUP端
vim /etc/keepalived/keepalived.conf
global_defs {
router_id LVS_KEEP02
}
vrrp_script check_nginx {
script “/script/check_nginx.sh”
interval 2 #检查间隔时间
weight -51 #失败时优先级的变化
fall 2 #失败几次后真正确认为失败
rise 1 #成功几次后确认为成功
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.125.192.100/24
}
track_script {
check_nginx
}
}