WIUNIX ACADEMY
HAProxy + Keepalived: build an active/standby VRRP load balancer
Build two HAProxy nodes with a shared virtual IP, route traffic to healthy HTTP backends and verify real failover with Keepalived VRRP—on your selected Linux version.
Make this guide yoursYOUR SYSTEM. YOUR STEPS.
Where are you working?
Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.
USE YOUR OWN VALUES
Configure this tutorial
Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.
Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.
Set values for my environment8 editable values
THE OUTCOME
What will you have at the end?
Route real HTTP requests through one floating VIP, confirm exactly one owner, then stop the active load balancer and verify a third client still reaches a healthy backend after VIP transfer.
Supported operating systems and versions
Documentation-reviewed on 2026-11-05: Ubuntu 26.10, 26.04/24.04/22.04 LTS; Debian 13/12; standard current RHEL, Rocky and AlmaLinux 10.2/9.8; Arch/Manjaro rolling. This is a fresh disposable two-VM private HTTP lab, not an integration into an existing proxy. RPM uses native repositories, firewalld and SELinux; Arch uses a full rolling update and /usr/bin launchers. No failover or distribution VM was executed for this revision; example output is illustrative. Debian 12 LTS package coverage and Ubuntu 26.10’s short support window need review for a real deployment.
Before you begin
- Two fresh disposable systemd VMs of the same selected distribution, with sudo, snapshots and independent console access; neither HAProxy nor Keepalived nor the tutorial checker identity is already installed. Do not run this installation during an incident.
- One approved unused IPv4 virtual address in the same private broadcast domain as both node interfaces; the network must permit VIP ARP ownership movement and peer-to-peer VRRP IP protocol 112.
- Two functioning, independently supervised HTTP backend services with a readiness endpoint that returns HTTP 200. Application response and readiness checks must be reachable from both load balancers.
- Administrative control of host and provider firewalls. A third client to verify the VIP, and permission to run a short disruptive failover test.
- Lab-only plaintext HTTP on a private subnet. For Internet publication, design a separately reviewed TLS and application-security layer.
LET’S BUILD
Identify the two load-balancer hosts
We will give a private HTTP service one address that can move between two independent load balancers. Use two fresh disposable VMs and a third client; VRRP needs an approved shared layer-2 network and a provider that permits secondary-IP ownership and gratuitous ARP movement. Unicast peer advertisements do not remove those address-delivery requirements.
Set the form to the real node, backend, VIP and interface values before copying commands. The VIP must be reserved and unused, and must not be statically assigned to either VM. The form enforces network membership and uniqueness; it does not discover whether another machine already owns that address. The network prefix comes from your CIDR, not a hard-coded /24.
Confirm systemd is PID 1 and port 80 has no unrelated listener. Keep separate console access. VRRP is an election protocol without fencing or quorum here: a network partition can make both nodes master, so prevent client access whenever ownership is ambiguous.
LB-01 and LB-02 · each server terminal · read-only inspection with sudo for socket ownership
cat /etc/os-release
ps -p 1 -o comm=
ip -br -4 address
ip -4 route
sudo ss -ltnp | grep -E ":80[[:space:]]" || trueBoth machines match the selected, reviewed Linux version; PID 1 is systemd. Their real interface addresses share the approved network and port 80 has no unexpected owner.
LET’S BUILD
Guard the fresh lab before package installation
Use two disposable fresh VMs. This guard refuses existing application directories, units, masks, backup paths and checker identities; it does not migrate an existing load balancer. It masks the new units before installation so package scripts cannot expose an unconfigured listener or advertise a sample VIP.
If it stops, inspect that VM and choose a fresh one. Do not remove the conflicting paths or unmask someone else’s service to bypass the guard. A failed installation may leave these two lab masks; retain them until this lab is configured or retire the disposable VM.
Both fresh lab VMs · sudo · run once before installing packages
sudo bash <<'ROOT'
set -euo pipefail
for path in /etc/haproxy /etc/keepalived /root/wiunix-academy-ha-backup /usr/local/sbin/wiunix-check-haproxy /etc/systemd/system/haproxy.service /etc/systemd/system/keepalived.service; do
if [ -e "$path" ] || [ -L "$path" ]; then
printf 'STOP: existing path: %s\n' "$path" >&2; exit 1
fi
done
if getent passwd academy-vrrp >/dev/null || getent group academy-vrrp >/dev/null; then
echo 'STOP: checker identity already exists' >&2; exit 1
fi
for unit in haproxy keepalived; do
if [ "$(systemctl show "$unit.service" -p LoadState --value)" != not-found ]; then
echo "STOP: existing unit $unit" >&2; exit 1
fi
done
install -d -m 0700 /root/wiunix-academy-ha-backup
systemctl mask haproxy.service keepalived.service
ROOTNo existing deployment was found; a fresh root-only backup directory and two lab-created masks now exist.
LET’S BUILD
Install packages from your distribution
Install from the selected distribution’s official repositories after the fresh-lab guard has masked both services. Review the complete transaction; a package operation is a planned change on these disposable VMs, not a troubleshooting command for a serving node. Curl and packet-capture tools are installed now, before backend checks.
Keep both services masked until their reviewed configuration is ready. Ubuntu/Debian use /usr/sbin launchers; Arch/Manjaro package binaries live in /usr/bin. Inspect the actual systemd ExecStart as well: a custom drop-in, extra configuration directory or different executable changes what the service loads. Stop and reconcile unexpected unit overrides rather than assuming a manual config check covers them.
LB-01 and LB-02 · server terminal with sudo
sudo pacman -Syu haproxy keepalived curl iproute2 tcpdump shadow
pacman -Q haproxy keepalived
sudo /usr/bin/haproxy -v
sudo /usr/bin/keepalived --version
sudo cat /usr/lib/systemd/system/haproxy.service /usr/lib/systemd/system/keepalived.serviceBoth binaries print versions and the package installation succeeds. No claim about frontend, backend or VIP health follows from this alone.
LET’S BUILD
Prove each application backend is ready
Before configuring failover, have two independently supervised HTTP applications listening on app1 = 10.20.30.21:8080 and app2 = 10.20.30.22:8080. Both must return HTTP 200 to GET /healthz under the Host value lab.internal, and serve an actual response at /. Adapt the addresses, port, Host and readiness path to your application; this guide does not create or expose an unmaintained demo web server.
Run these requests from both load balancers. HTTP 200 from the readiness endpoint matters more than a listening TCP port; if an application returns redirects, login HTML or errors, fix its health endpoint before continuing. This test is only backend readiness, not VIP failover.
LB-01 and LB-02 · ordinary shell user · replace backend example values on each node
curl --noproxy '*' -i --max-time 4 -H 'Host: lab.internal' http://10.20.30.21:8080/healthz
curl --noproxy '*' -i --max-time 4 -H 'Host: lab.internal' http://10.20.30.22:8080/healthz
curl --noproxy '*' --fail --silent --show-error --max-time 4 -H 'Host: lab.internal' http://10.20.30.21:8080/EXAMPLE ONLY — supplied by an application, not measured on WIUNIX production:
HTTP/1.1 200 OK
Content-Type: text/plain
OKBoth health requests return status 200, and the application root responds. If only one backend passes, do not call this a healthy two-backend design.
LET’S BUILD
Review the network and firewall path
Agree on one unused VIP and one unused VRID with the network operator. Unicast VRRP uses IP protocol 112, not TCP or UDP port 112; permit it in both directions only between the two physical node addresses. Permit client TCP 80 to the VIP and the physical listeners, and backend TCP 8080 only from both load balancers. On a cloud fabric that rejects secondary IP/ARP movement, stop here and use its supported floating-IP or managed load-balancer mechanism instead.
The optional commands below are for nodes whose active firewall is UFW. They restrict the sample lab HTTP ingress to the example subnet; the VRRP allowance is limited to the two example peers on ens18. If UFW is not installed or inactive, no host rules are changed. Inspect your nftables, upstream ACLs and provider policy separately; never disable the firewall or blindly replace an existing policy.
Keep console or out-of-band administrative access before altering rules. The sample unencrypted HTTP endpoint belongs on a private lab network, not the public Internet.
LB-01 and LB-02 · sudo where UFW is the active firewall · replace peer subnet and interface before use
if command -v ufw >/dev/null && sudo ufw status | grep -q '^Status: active'; then
sudo ufw allow in on ens18 from 10.20.30.0/24 to any port 80 proto tcp comment 'Academy HA HTTP lab'
sudo ufw allow in on ens18 from 10.20.30.11 to any proto vrrp comment 'Academy VRRP LB01'
sudo ufw allow in on ens18 from 10.20.30.12 to any proto vrrp comment 'Academy VRRP LB02'
sudo ufw status numbered
else
printf '%s\n' 'UFW not active: check your actual host/provider firewall manually'
fiThe real network and active security policy allow peer-to-peer IP protocol 112, permitted lab clients can reach TCP 80, and backends accept TCP 8080 from both balancers. UFW messages are not proof of upstream reachability.
LET’S BUILD
Save the current configuration before editing
Save the newly installed vendor files before replacing them. The fresh-lab guard already reserved a root-only backup directory; this step refuses to overwrite saved backups and records when a vendor file is absent. These are factory-file snapshots, not a backup of a pre-existing production service.
Create a dedicated non-login checker account so the group name does not depend on nobody/nogroup distribution conventions. Both services stay masked. If any command fails, resolve it before continuing; never rerun the whole install over partial state without inspecting it.
LB-01 and LB-02 · sudo · dedicated nodes only
sudo bash <<'ROOT'
set -euo pipefail
test -d /root/wiunix-academy-ha-backup
for name in haproxy keepalived; do
case "$name" in
haproxy) path=/etc/haproxy/haproxy.cfg ;;
keepalived) path=/etc/keepalived/keepalived.conf ;;
esac
test ! -e "/root/wiunix-academy-ha-backup/$name.cfg.before"
test ! -e "/root/wiunix-academy-ha-backup/$name.absent"
if [ -L "$path" ]; then echo "STOP: symlink $path" >&2; exit 1; fi
if [ -f "$path" ]; then
cp -a "$path" "/root/wiunix-academy-ha-backup/$name.cfg.before"
else
touch "/root/wiunix-academy-ha-backup/$name.absent"
fi
done
install -d -o root -g root -m 0755 /etc/haproxy /etc/keepalived /usr/local/sbin
groupadd --system academy-vrrp
useradd --system --gid academy-vrrp --no-create-home --home-dir /nonexistent --shell /usr/bin/nologin academy-vrrp
getent passwd academy-vrrp
getent group haproxy
ROOTThe backup directory is root-only and contains the original HAProxy file, plus the Keepalived file when one existed.