在Centos 7中配置如下:
yum install keepalive -y
版本:
Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
vrrp_script chk_down {
script"[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
interval 1
weight -2
}
track_script {
chk_down
}
touch /etc/keepalived/down #无法手动切换主从
查看日志
Keepalived_vrrp[9772]: Unable to access script [[
Dec 5 05:06:18 node71 Keepalived_vrrp[9772]: Disabling track script chk_down since not found
解决:
vrrp_script chk_down {
#script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
script "/etc/keepalived/keep_down.sh"
interval 1
}
cat etc/keepalived/keep_down.sh
#!/bin/bash
if [ -f /etc/keepalived/down ];then
weight -2
fi
VRRP script(s)
Adds a script to be executed periodically. Its exit code will be
# recorded for all VRRP instances which are monitoring it.
vrrp_script <SCRIPT_NAME> {
script <STRING>|<QUOTED-STRING> # path of the script to execute
interval <INTEGER> # seconds between script invocations, default 1 second
timeout <INTEGER> # seconds after which script is considered to have failed
weight <INTEGER:-254..254> # adjust priority by this weight, default 0
rise <INTEGER> # required number of successes for OK transition
fall <INTEGER> # required number of successes for KO transition
user USERNAME [GROUPNAME] # user/group names to run script under
# group default to group of user
init_fail # assume script initially is in failed state
}
转载于:https://blog.51cto.com/shadowhk/2047662