! Configuration File for keepalived global_defs { router_id OAMHA } #监控服务httpd, mysql等 vrrp_script check_service_health { script "/etc/keepalived/check_service_health.sh" #每2s检查一次 interval 3 #每次检查-10 weight -10 fail 3 #失败次数,如果请求失败2次就认为此节点资源发生故障将进行切换 rise 1 #监测成功就立即成功,如果请求一次成功就默认此节点资源恢复正常 } vrrp_instance VI_1 { state {{ ha_backup.instance_state }} interface {{ ha_backup.ethname }} virtual_router_id {{ ha_backup.oam_virtual_router_id }} priority 10 advert_int 1 authentication { auth_type PASS auth_pass oamha } virtual_ipaddress { {{ ha_backup.virtual_ip }} } #触发的脚本 track_script { check_service_health #检测脚本,上面配置的 } }