keepalived master配置:
# cat /etc/keepalived/keepalived.conf
global_defs {
script_user root root
}
vrrp_script chk_port_ceph {
script "/etc/keepalived/check_ports_ganesha"
interval 3
weight -50
}
vrrp_instance VI_2 {
state MASTER
interface bond0
nopreempt
virtual_router_id 14
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass vLKKIb310LIvN6gj
}

virtual_ipaddress {
192.168.1.27/24 dev bond0 label bond0:ganesha
}
track_script {
chk_port_ceph
}
notify_master "systemctl restart nfs-ganesha"
notify_backup "systemctl stop nfs-ganesha"
notify_fault "systemctl stop nfs-ganesha"
notify_stop "systemctl stop nfs-ganesha"
}

keepalived backup配置:
# cat /etc/keepalived/keepalived.conf
global_defs {
script_user root root
}
vrrp_script chk_port_ceph {
script "/etc/keepalived/check_ports_ganesha"
interval 3
weight -50
}
vrrp_instance VI_2 {
state BACKUP
nopreempt
interface bond0
virtual_router_id 14
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass vLKKIb310LIvN6gj
}

virtual_ipaddress {
192.168.1.27/24 dev bond0 label bond0:ganesha
}

track_script {
chk_port_ceph
}
notify_master "systemctl start nfs-ganesha"
notify_backup "systemctl stop nfs-ganesha"
notify_fault "systemctl stop nfs-ganesha"
}

检测脚本
# cat check_ports_ganesha
#!/bin/sh
vip=192.168.1.27
if ! /sbin/ip addr | grep -q $vip; then
exit
fi

systemctl status nfs-ganesha >/dev/null
if [ $? -ne 0 ]; then
systemctl restart nfs-ganesha
systemctl status nfs-ganesha >/dev/null
if [ $? -eq 0 ]; then
echo 0
else
systemctl stop keepalived
fi
fi