1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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