32.11. Redundant LVS Directors and Failover Verification
The director holds the virtual address and the IPVS table, which makes it a single point of failure in all three modes. The fix is the chapter's standing pattern: two directors, one address owner, and - new in this section - a channel that copies connection state between them.
32.11.1. Combining VRRP Address Ownership with IPVS Service Configuration
The redundant configuration is the union of the previous sections: the
VRRP election from section 32.9, carrying both LVS addresses, plus the
direct-routing and tunneling services from sections 32.10.6 and 32.10.7.
Write /etc/keepalived/keepalived.conf on both directors; the
listing is ha1's, and the per-node values are the ones marked:
global_defs {
router_id ha1 # ha2 on the second node
lvs_sync_daemon eth1
enable_script_security
script_user root
}
vrrp_instance VI_1 {
state BACKUP
interface eth1
virtual_router_id 55 # identical on both nodes
priority 100 # 90 on the second node
advert_int 1
preempt_delay 5
unicast_src_ip 192.168.232.11 # the node's own address
unicast_peer {
192.168.232.12 # ha1 lists ha2; ha2 lists ha1
}
virtual_ipaddress {
192.168.232.161/24 dev eth1
192.168.232.162/24 dev eth1
}
}
virtual_server 192.168.232.161 8081 {
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
real_server 192.168.232.13 8081 {
weight 1
TCP_CHECK {
connect_timeout 2
retry 2
delay_before_retry 1
}
}
real_server 192.168.232.14 8081 {
weight 1
TCP_CHECK {
connect_timeout 2
retry 2
delay_before_retry 1
}
}
}
virtual_server 192.168.232.162 8081 {
delay_loop 3
lb_algo rr
lb_kind TUN
protocol TCP
real_server 192.168.232.13 8081 {
weight 1
TCP_CHECK {
connect_timeout 2
retry 2
delay_before_retry 1
}
}
real_server 192.168.232.14 8081 {
weight 1
TCP_CHECK {
connect_timeout 2
retry 2
delay_before_retry 1
}
}
}
Both directors run the same IPVS table; only the VRRP election
distinguishes them. Restart the service on both. On ha1, as john:
$ sudo systemctl restart keepalived
On ha2, the same. The higher-priority node takes both addresses. On
ha1, as john:
$ ip -4 -br addr show eth1
eth1 UP 192.168.232.11/24 192.168.232.161/24 192.168.232.162/24
Through the client, on lbcli, as john:
$ for i in 1 2; do curl -s --max-time 5 http://192.168.232.161:8081/ | head -1; done
backend=lbclient
backend=haclient
And the table the winning director holds. On ha1, as john:
$ sudo ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.232.161:8081 rr
-> 192.168.232.13:8081 Route 1 0 3
-> 192.168.232.14:8081 Route 1 0 3
TCP 192.168.232.162:8081 rr
-> 192.168.232.13:8081 Tunnel 1 0 2
-> 192.168.232.14:8081 Tunnel 1 0 2
Two services, four real servers, one owner.
32.11.2. Connection Synchronization and Its Limits During Director Failover
The lvs_sync_daemon eth1 line in global_defs starts the kernel's
IPVS connection synchronization daemon on the service interface: the
MASTER director sends connection-state entries, and the BACKUP
receives them into its own table so that a failover does not reset every
established connection to "unknown". Keepalived's documentation extends
the directive to bind the sync role to a VRRP instance -
lvs_sync_daemon eth1 VI_1 - so the sync direction follows address
ownership automatically; the configuration above uses the shorter
interface-only form, which the running Keepalived accepts.
The limits are as important as the feature. The sync daemon copies connection table entries, periodically - it is not a transaction log and does not guarantee that a connection in an intermediate state survives a failover between syncs. And it synchronizes nothing else: health-check state, persistence maps beyond their entries, and anything the application holds are each their own problem. The practice lab configured the sync daemon and verified that new connections were served immediately after a director failover; it did not attempt to prove that an established long-lived connection survived the transition, and this chapter does not claim it.
32.11.3. Verifying NAT, Direct-Routing, and Tunneling Paths with Packet Captures
Each forwarding mode makes specific, checkable claims about packets.
The command sequences below are the verification procedure, not captured
output; the fields each mode should show are derived from the packet
path of Figure 32.6. Run them while sending a
few requests from lbcli:
On the director, NAT mode - watch both directions of one connection:
$ sudo tcpdump -ni eth1 host 192.168.232.15 and tcp port 80
Expected: inbound packets with destination 192.168.232.160:80 (the client's request), and the same packets leaving with destination rewritten to a real server's :8081; replies arriving from the real server and leaving toward the client with source rewritten back to 192.168.232.160. Two address pairs per request: the NAT contract.
On the director, direct routing - include the Ethernet header:
$ sudo tcpdump -ni -e eth1 host 192.168.232.15 and tcp port 8081
Expected: the same IP addresses on every hop - destination 192.168.232.161 throughout - with the MAC address changing between the client-to-director frame and the director-to-backend frame, and no reply packets from the backend traversing the director at all.
On the director, tunneling - match the encapsulation protocol:
$ sudo tcpdump -ni eth1 proto 4
Expected: packets with outer addresses director-to-backend
(192.168.232.11 to 192.168.232.13 or .14), protocol 4 (IPIP); each
carries the original client-to-VIP packet inside. On a backend, the same
command shows the encapsulated packets arriving, and
sudo tcpdump -ni tunl0 shows them after decapsulation with the
original addresses.
If a mode is not working, these captures localize the failure faster
than any amount of ipvsadm staring: rewriting absent (NAT misrouting),
MAC unchanged (DR forwarding not engaged), no proto-4 packets (TUN
encapsulation or ipip module missing), or answers arriving at the
director from a backend (a return route that should have been direct).
32.11.4. Testing Backend Failure, Director Loss, Advertisement Partitions, and Recovery
Backend failure was captured in section 32.10.5 and the draining
practice is in section 32.10.8; the new event here is losing the
director. Stop the MASTER's Keepalived - the abrupt form of a director
crash. On ha1, as john:
$ sudo systemctl stop keepalived
The command normally prints nothing. The VRRP silence triggers the
BACKUP's MASTER_DOWN timer, and within seconds the addresses and the
table move. On ha2, as john:
$ ip -4 -br addr show eth1
eth1 UP 192.168.232.12/24 192.168.232.100/24 192.168.232.161/24 192.168.232.162/24
$ sudo ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.232.161:8081 rr
-> 192.168.232.13:8081 Route 1 0 1
-> 192.168.232.14:8081 Route 1 0 1
TCP 192.168.232.162:8081 rr
-> 192.168.232.13:8081 Tunnel 1 0 0
-> 192.168.232.14:8081 Tunnel 1 0 0
(The .100 address riding along on ha2 is the inherited NFS service
address from section 32.8.2 - present, owned by Pacemaker, and not this
section's business.) The client asks nothing about any of this. On
lbcli, as john:
$ for i in 1 2; do curl -s --max-time 5 http://192.168.232.161:8081/ | head -1; done
backend=lbclient
backend=haclient
New connections served by the surviving director immediately. Bring the
failed director back. On ha1, as john:
$ sudo systemctl start keepalived
Preemption applies as configured: after the preempt_delay, the
higher-priority node reclaims the addresses. On ha1, as john:
$ ip -4 -br addr show eth1
eth1 UP 192.168.232.11/24 192.168.232.161/24 192.168.232.162/24
And the client, indifferent throughout, exercises both services. On
lbcli, as john:
$ for i in 1 2; do curl -s --max-time 5 http://192.168.232.162:8081/ | head -1; done
backend=lbclient
backend=haclient
The remaining scenario is an advertisement partition between directors - the deliberately created duplicate-ownership state of section 32.9.5. Its consequence for an LVS pair is the same as for a plain VRRP pair, plus one: two directors running the same table at once means two independent schedulers, both forwarding, both convinced they own the address. The client's connections land on whichever director the switch prefers, and each restarts its half of the connection state. The prevention is section 32.9.5's lesson: permit protocol 112 between directors, and monitor for the duplicate state instead of assuming the protocol's silence tolerance is a safety mechanism.
32.11.5. Checking New and Established Client Connections, Persistence, and Failback
What the captured sequence proves, precisely:
- New connections worked immediately after the director failover, on both the direct-routing and the tunneling services, and after failback.
- Scheduling stayed
rracross the transition, with requests alternating between backends afterward as before. - Persistence was not configured on either redundant service, so nothing pinned clients across the failover; the NAT phase of section 32.10.5 is the captured example of persistence within one director's lifetime.
What it does not prove, stated once: survival of an established connection across the director transition. The sync daemon exists for that case, was configured for it, and may well deliver it - but the lab tested only new connections after the failover, and a deployment that depends on established-connection survival (long-lived SSH tunnels through an LVS pair, database pools with server-side state) must test it with its own traffic before relying on it. The test is the same shape as the captured one: open a connection, fail the director, watch the connection, and record what actually happens.
Failback deserves the last word because it is the operation nobody
schedules. The captured failback moved the addresses back to ha1
after preempt_delay, interrupting whatever connections had settled on
ha2 during the outage. A pool that fails over at 2 a.m. and fails back
automatically at 2:04 has had two outages, not one. nopreempt
(section 32.9.4) keeps the service wherever it landed until an
administrator decides otherwise; for director pairs, that is usually the
right default, with failback as a planned, announced event.