使用 keepalived 高可用 nginx
主节点配置:
global_defs {
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_nginx {
script "/usr/bin/killall -0 nginx && exit 0 || exit 1"
interval 1
weight -10
fall 2
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 55
priority 100
advert_int 1
# nopreempt
authentication {
auth_type PASS
auth_pass 12345678
}
virtual_ipaddress {
172.20.47.202
}
track_script {
chk_nginx
}
}
从节点配置:
global_defs {
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_script chk_nginx {
script "/usr/bin/killall -0 nginx && exit 0 || exit 1"
interval 1
weight -10
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 55
priority 95
advert_int 1
# nopreempt
authentication {
auth_type PASS
auth_pass 12345678
}
virtual_ipaddress {
172.20.47.202
}
track_script {
chk_nginx
}
}
参考:
https://www.keepalived.org/pdf/UserGuide.pdf
https://github.com/acassen/keepalived