一、基本信息
代理主机01:192.168.198.99
代理主机02:192.168.198.98
虚拟IP:192.168.198.88
网卡:ens33
二、配置文件
1. /etc/hosts
192.168.198.99 proxy-1
192.168.198.98 proxy-2
2. /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
chenhaikun8@gmail.com
}
notification_email_from keepalived@vmware.com
smtp_server 127.0.0.1
router_id proxy-1
vrrp_mcast_group4 224.4.4.4
}
vrrp_script chk_proxy {
script "/etc/keepalived/proxy_check.sh"
interval 2
weight -2
}
vrrp_instance VI_1 {
state BACKUP
nopreempt
interface ens33
virtual_router_id 11
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.198.88/24 dev ens33 label ens33:1
}
track_script {
chk_proxy
}
}
3. /etc/keepalived/proxy_check.sh
#!/bin/bash
# === nginx prxy check script ===
netstat -nlpt | grep -w "80" &>> /dev/null
if [ $? -ne 0 ]
then
systemctl stop keepalived
fi
exit 0