兩個節(jié)點安裝keepalived
yum install keepalived haproxy -y
修改keepalived配置文件
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/var/mxscripts/check_haproxy.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface ens160
virtual_router_id 51
priority 120
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
10.0.10.99
}
}
check_haproxy.sh腳本
if [ $(systemctl status haproxy|grep active|grep running|wc -l) -eq 0 ];then
systemctl start haproxy
fi
sleep 2
if [ $(systemctl status haproxy|grep active|grep running|wc -l) -eq 0 ];then
systemctl stop keepalived
fi
從節(jié)點master改成backup
優(yōu)先級調(diào)第一點
其余一致
修改內(nèi)核選項,
否則備份節(jié)點無VIP則haproxy綁定失敗無法啟動
net.ipv4.ip_nonlocal_bind = 1
兩個節(jié)點啟動服務(wù)
systemctl start keepalived
systemctl enable keepalived