keepalived
Notes:
- If several backup servers have the same priority, the backup server with the highest IP address value becomes the master server.
Prerequisites:
1sysctl net.ipv4.ip_forward=1 ## Enable IP Forwarding.
2modprobe ip_vs; lsmod | grep ip_vs ## ip_vs module is present/loaded.
3echo ip_vs >> /etc/modules-load.d/modules.conf ## Ensure ip_vs module is loaded on boot.
4sysctl net.ipv4.ip_nonlocal_bind=1 ## If something else needs to bind to the VIP. (eg: HAProxy, Load Balancer, etc.)
Example config:
Show Sample Config
## UNICAST:
vrrp_script curlLocalHost {
script "/bin/curlLocalHost.sh"
weight -10
interval 2
fall 2
rise 2
}
vrrp_instance VRRP1 {
state BACKUP
interface eth0
virtual_router_id 41
priority 100
unicast_src_ip 77.9.61.[46/47/48]
unicast_peer {
77.9.61.46
77.9.61.47
77.9.61.48
}
virtual_ipaddress {
77.9.61.45
}
track_script {
curlLocalHost
}
}
Example Track Script (curlLocalHost.sh):
#!/bin/bash
"/bin/curl localhost"