sudo apt install haproxy keepalived -y
- /etc/haproxy/haproxy.cfg
...
frontend stats
mode http
bind *:8404
stats enable
stats uri /stats
stats refresh 2s
stats admin if LOCALHOST
frontend localnodes
bind *:80
mode tcp
default_backend nodes
backend nodes
mode tcp
balance leastconn
server web01 192.168.25.188:80 check inter 2s
server web02 192.168.25.189:80 check inter 2s
- /etc/keepalived/keepalived.conf
vrrp_track_process track_haproxy {
process haproxy
delay 1
}
vrrp_instance VI_1 {
state MASTER
# state BACKUP
interface eth1
virtual_router_id 101
priority 20
# priority 10
advert_int 1
authentication {
auth_type PASS
auth_pass 1qaz2wsx
}
virtual_ipaddress {
192.168.25.185
}
track_process {
track_haproxy
}
}
systemctl restart keepalived.service