用keepalived配置了一个主备tomcat,配置文件如下:
! Configuration File for keepalived
global_defs {
notification_email {
zhouxiao@example.com
itsection@example.com
}
notification_email_from itsection@example.com
smtp_server mail.example.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_tomcat {
#script "killall -0 nginx"
script "/etc/keepalived/tomcat_check.sh"
interval 2
weight -5
fall 3
rise 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
mcast_src_ip 192.168.128.150
virtual_router_id 51
priority 100
advert_int 2
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.128.152
}
track_script {
chk_tomcat
}
notify_master "/d/d_ctl.sh start"
notify_backup "/d/d_ctl.sh stop"
}
切换时,脚本始终不执行,过google了半天,发现有一个这样写到:
原文链接:https://serverfault.com/questions/709428/track-script-doesnt-work-after-keepalived-update
chcon -t keepalived_unconfined_script_exec_t /etc/keepalived/chk_available.sh
我的是这样执行:(主keepalived和备keepalived都执行)
chcon -t keepalived_unconfined_script_exec_t /d/d_ctl.sh
再重启keepalived测试,完全解决