← Start of tutorial

WIUNIX ACADEMY

HAProxy + Keepalived: build an active/standby VRRP load balancer

Page 4 of 6. Review the earlier steps and prerequisites before continuing.

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

AlmaLinux 9.8Reviewed against official documentation ·

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
14

LET’S BUILD

Check both VRRP files before enabling ownership

Keepalived supports a configuration-test mode. Run the command on each node and read all warnings, not just the exit status. Check interface names, script permissions and the source/peer direction. A syntactically valid file still cannot prove that the network admits VRRP advertisements or moves the VIP.

Keepalived may report script-security or permission problems, which must be fixed before allowing a VRRP election.

Bash

LB-01 and LB-02 · sudo to validate · unprivileged script check

sudo /usr/sbin/keepalived --config-test -f /etc/keepalived/keepalived.conf
sudo -u academy-vrrp /usr/local/sbin/wiunix-check-haproxy
check_status=$?
printf 'script exit=%s\n' "$check_status"
test "$check_status" -eq 0
How do I know it worked?

No blocking configuration/security diagnostics; the script returns 0. Network reachability and unique VIP ownership still need verification.

15

LET’S BUILD

Start VRRP and inspect election messages

Once both HAProxy nodes return healthy responses and network peer rules are ready, unmask and start this lab’s Keepalived unit on both nodes. Both start in BACKUP intentionally; startup order can affect the initial holder even with different priorities.

Inspect real MASTER/BACKUP/FAULT transitions and script-security diagnostics. Both daemons being active is normal; it does not prove one VIP owner. Never force MASTER to conceal FAULT.

Bash

LB-01 and LB-02 · each terminal · sudo for service changes and journal

sudo /usr/sbin/keepalived --config-test -f /etc/keepalived/keepalived.conf &&
sudo systemctl unmask keepalived &&
sudo systemctl enable --now keepalived
systemctl is-active keepalived
sudo journalctl -u keepalived -n 40 --no-pager
EXAMPLE OUTPUT
EXAMPLE OUTPUT ONLY — host names and log timestamps vary:
LB-01: (VI_HTTP) Entering MASTER STATE
LB-02: (VI_HTTP) Entering BACKUP STATE
How do I know it worked?

Keepalived is active on both hosts; election logs show one MASTER and one BACKUP. If either is FAULT, diagnose rather than forcing a MASTER state.

16

LET’S BUILD

Prove exactly one node currently holds the VIP

Inspect addresses on the actual HA interface separately on LB-01 and LB-02. Exactly one should show the additional VIP and both should retain their individual node address. Do not accept "the keepalived process is running" as evidence.

If both show the VIP, suspect missing peer advertisements, wrong VRID/interface or a network split-brain condition. Isolate client ingress and fix the network before proceeding; sending traffic to duplicated addresses is unsafe.

Bash

Run separately on LB-01 and LB-02 · inspect actual interface

ip -br -4 address show dev ens18
sudo journalctl -u keepalived -n 25 --no-pager
EXAMPLE OUTPUT
EXAMPLE ONLY — separate observations:
LB-01: ens18 UP 10.20.30.11/24 10.20.30.100/24
LB-02: ens18 UP 10.20.30.12/24
How do I know it worked?

Only one physical node contains 10.20.30.100/24 on the selected interface, and peer logs agree about MASTER and BACKUP.

17

LET’S BUILD

Request the VIP from an independent client

Use a third client on an explicitly permitted network path, not a shell on the current master. Send a real application request through the VIP and demand a successful HTTP status. The remote IP reported by curl must be the VIP; the observed HTTP response must come from your intended application.

The combination of unique VIP ownership on the nodes, a successful off-node HTTP request and the application response supports initial end-to-end availability. It does not yet demonstrate failover or guarantee that existing long-lived connections survive a node crash.

The panel prints the returned application body after checking status and peer address. Compare it with your intended application; a generic 200 page from the wrong service is not a pass. The temporary body file is removed when the panel exits.

Bash

A third Linux or macOS client on the permitted lab subnet · ordinary user; replace VIP/Host

(
set -euo pipefail
body=$(mktemp)
trap 'rm -f -- "$body"' EXIT
result=$(curl --noproxy '*' --silent --show-error --connect-timeout 3 --max-time 8 \
  -H 'Host: lab.internal' -o "$body" -w '%{http_code} %{remote_ip}' \
  http://10.20.30.100/)
printf 'HTTP status and peer: %s\n' "$result"
case "$result" in
  2[0-9][0-9]\ *) : ;;
  *) echo 'FAIL: expected HTTP 2xx without redirect' >&2; exit 1 ;;
esac
test "${result#* }" = '10.20.30.100'
cat -- "$body"
printf '\nCompare this response with the intended application.\n'
)
EXAMPLE OUTPUT
EXAMPLE OUTPUT ONLY — not a measured deployment:
HTTP status and peer: 200 10.20.30.100
How do I know it worked?

The request exits successfully and shows a 2xx application response from the VIP. A connection to a physical node address is not an equivalent test.

18

LET’S BUILD

Simulate failure of the actual active balancer

In a planned maintenance window, identify the current VIP owner from the previous step. Only on that host, stop HAProxy—not Keepalived—so the HTTP health script fails and Keepalived can move the VIP. The command below assumes LB-01 is the MASTER; if LB-02 owns the VIP, run the stop on LB-02 instead.

Expect a short interruption while repeated checks fail, the VRRP election settles and neighbor caches learn the new owner. This test intentionally disrupts an active service: do not run it against real users without permission, rollback and monitoring.

Wait long enough for the configured check/fall policy before inspecting addresses. Do not simultaneously stop both balancers.

Bash

ONLY the currently active VIP owner (LB-01 in the example) · sudo; disruptive planned test

sudo systemctl stop haproxy
sleep 10
ip -br -4 address show dev ens18
sudo journalctl -u keepalived -n 30 --no-pager
How do I know it worked?

The active node loses its VIP after the failed health threshold; the healthy peer is eligible to acquire it. Confirm on BOTH hosts in the next step.

19

LET’S BUILD

Prove new VIP ownership on both load balancers

After the old active HAProxy is stopped, inspect interface addresses separately on LB-01 and LB-02. The old owner must lose the VIP and the healthy standby must gain it. Both owning it would be split brain.

This checks only address ownership. Continue with the separate off-node HTTP request to prove that the application is available.

Bash

Run separately on LB-01 and LB-02, not on the external client.

ip -br -4 address show dev ens18
EXAMPLE OUTPUT
EXAMPLE ONLY — after LB-01 stops:
LB-01: ens18 UP 10.20.30.11/24
LB-02: ens18 UP 10.20.30.12/24 10.20.30.100/24
How do I know it worked?

The VIP exists only on the formerly standby load balancer.

Explore all tutorials ↗