apt install keepalived
Copy the following config to /etc/keepalived/keepalived.conf
and change it to fit your needs.
vrrp_instance LB_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
authentication {
auth_type PASS
auth_pass imasupersecurepassword
}
# add virtual router id as last argument
notify "/bin/sudo /opt/hcloud-failover/hcloud_failover.py 1"
}
On the second (and all other servers) change:
- the name of the vrrp instance (LB_1)
- the state (to BACKUP)
- the virtual_router_id to something unique
- the priority to something that matches your needs
- the unicast_src_ip to the ip of the local system
- the unicast_peer array to the ip addresses of all other systems
adduser keepalived_script
apt install sudo
vim /etc/sudoers.d/90-keepalived
keepalived_script ALL=NOPASSWD: /bin/ip*, /opt/hcloud-failover/hcloud_failover.py*
systemctl enable keepalived --now
Enjoy :)