High Availability
Konten ini belum tersedia dalam bahasa Anda.
Artikel ini belum diterjemahkan. Isi berikut berbahasa Inggris. Buka versi asli bahasa Inggris.
High Availability with VRRP
Section titled “High Availability with VRRP”Version key: 🟢 = 1.3+ · 🟡 = 1.4+ · 🟣 = 1.5+
VRRP (Virtual Router Redundancy Protocol) lets two or more VyOS routers share a virtual IP. If the master fails, a backup takes over — clients don’t notice.
Architecture
Section titled “Architecture” ┌─────────────────────────────┐ │ Virtual IP: .1 │ │ ┌─────────┐ ┌─────────┐ │ │ │ Router A │ │ Router B │ │ │ │ MASTER │ │ BACKUP │ │ │ │ .2 │ │ .3 │ │ │ └────┬─────┘ └────┬─────┘ │ │ │ │ │ └───────┼─────────────┼─────────┘ │ SWITCH │ ┌─────┴─────────────┴─────┐ │ 192.168.1.0/24 │ │ Gateway: 192.168.1.1 │ ← Virtual IP └─────────────────────────┘Basic VRRP 🟢 1.3+
Section titled “Basic VRRP 🟢 1.3+”Router A (master):
set interfaces ethernet eth1 address 192.168.1.2/24set interfaces ethernet eth1 vrrp vrrp-group 1set high-availability vrrp group LAN interface eth1set high-availability vrrp group LAN vrid 10set high-availability vrrp group LAN virtual-address 192.168.1.1/24set high-availability vrrp group LAN priority 200 # higher = masterset high-availability vrrp group LAN preempt trueset high-availability vrrp group LAN preempt-delay 60set high-availability vrrp group LAN hello-interval 1set high-availability vrrp group LAN authentication type plaintext-passwordset high-availability vrrp group LAN authentication plaintext-password 'vrrp-secret'Router B (backup):
set interfaces ethernet eth1 address 192.168.1.3/24set interfaces ethernet eth1 vrrp vrrp-group 1set high-availability vrrp group LAN interface eth1set high-availability vrrp group LAN vrid 10set high-availability vrrp group LAN virtual-address 192.168.1.1/24set high-availability vrrp group LAN priority 100 # lower = backupset high-availability vrrp group LAN authentication type plaintext-passwordset high-availability vrrp group LAN authentication plaintext-password 'vrrp-secret'Multiple VRIDs (Load Sharing)
Section titled “Multiple VRIDs (Load Sharing)”Split traffic across both routers for active-active:
# Router A — master for vrid 10, backup for vrid 20set high-availability vrrp group LAN-A interface eth1set high-availability vrrp group LAN-A vrid 10set high-availability vrrp group LAN-A virtual-address 192.168.1.1/24set high-availability vrrp group LAN-A priority 200
set high-availability vrrp group LAN-B interface eth1set high-availability vrrp group LAN-B vrid 20set high-availability vrrp group LAN-B virtual-address 192.168.1.2/24set high-availability vrrp group LAN-B priority 100
# Router B — master for vrid 20, backup for vrid 10# Set priorities reversedLAN clients use .1 or .2 as gateway — split them via DHCP or manual config.
WAN Failover (Dual WAN)
Section titled “WAN Failover (Dual WAN)”If each router has its own WAN:
# On both routers — SNAT to their respective WAN IPs# Use `translation address` instead of masquerade
# Router Aset nat source rule 100 outbound-interface name eth0set nat source rule 100 source address 192.168.1.0/24set nat source rule 100 translation address 203.0.113.10
# Router Bset nat source rule 100 outbound-interface name eth0set nat source rule 100 source address 192.168.1.0/24set nat source rule 100 translation address 203.0.113.11Configuration Sync
Section titled “Configuration Sync”VRRP handles IP failover, but you need config sync too. Options:
Manual Sync (simple)
Section titled “Manual Sync (simple)”# On master, after commit:saveScripted Sync
Section titled “Scripted Sync”Create /config/scripts/sync-config.sh:
#!/bin/bashBACKUP="192.168.1.3"REMOTE_USER="vyos"CONFIG="/config/config.boot"
rsync -avz $CONFIG $REMOTE_USER@$BACKUP:/config/config.boot.tmpssh $REMOTE_USER@$BACKUP "source /opt/vyatta/etc/functions/script-template; \ configure; load /config/config.boot.tmp; \ set high-availability vrrp group LAN priority 100; \ commit; save; exit"Cluster Config (VyOS 1.4+) 🟡
Section titled “Cluster Config (VyOS 1.4+) 🟡”# Experimental: config-sync featureset high-availability config-sync peer 192.168.1.3set high-availability config-sync sync-direction master-to-backupset high-availability config-sync sync-on-commitStateful Failover (Connection Tracking Sync) 🟡 1.4+
Section titled “Stateful Failover (Connection Tracking Sync) 🟡 1.4+”For seamless failover of active connections (NAT, firewall states):
# On master — sync state table to backupset high-availability vrrp group LAN sync-group LAN-SYNCset high-availability vrrp sync-group LAN-SYNC member LANset high-availability vrrp sync-group LAN-SYNC conntrack-sync interface eth1
# On backup — receiveset high-availability vrrp group LAN sync-group LAN-SYNCset high-availability vrrp sync-group LAN-SYNC member LANset high-availability vrrp sync-group LAN-SYNC conntrack-sync interface eth1
# Note: Both routers need a dedicated sync link (or use LAN).# The sync interface carries state table traffic.Monitoring & Health Checks 🟡 1.4+
Section titled “Monitoring & Health Checks 🟡 1.4+”Track Interface Status
Section titled “Track Interface Status”Drop priority if WAN goes down:
set high-availability vrrp group LAN track interface eth0set high-availability vrrp group LAN track interface eth0 priority-cost 150# If eth0 goes down, priority drops by 150 → backup takes overScript-based Health Check
Section titled “Script-based Health Check”# Health check scriptset high-availability vrrp group LAN health-check script /config/scripts/health-check.shset high-availability vrrp group LAN health-check interval 5
# /config/scripts/health-check.sh:#!/bin/bash# Exit 0 = healthy, exit 1 = unhealthy (trigger failover)ping -c 1 -W 2 8.8.8.8 > /dev/null 2>&1exit $?Verify
Section titled “Verify”# VRRP statusshow high-availability vrrp summaryshow high-availability vrrp group LANshow high-availability vrrp statistics
# Who is master?show high-availability vrrp group LAN | grep -i state
# Conntrack sync statusshow high-availability vrrp sync-group
# Interface trackingshow high-availability vrrp trackComplete HA Config (Reference)
Section titled “Complete HA Config (Reference)”Two routers, shared LAN, dual WAN, config sync:
Router A (192.168.1.2) Router B (192.168.1.3) WAN: 203.0.113.10 WAN: 203.0.113.11 Priority: 200 Priority: 100 Virtual IP: 192.168.1.1 Virtual IP: 192.168.1.1Both routers share the same base config except:
- Real IP on eth1 (.2 vs .3)
- VRRP priority (200 vs 100)
- SNAT WAN IP
Template approach: maintain ONE config, deploy with sed to customize per-router values.
Pitfalls
Section titled “Pitfalls”- Split brain: Both routers master → both respond to virtual IP ARP. Caused by: no multicast between them, mismatched VRID, authentication mismatch.
- No state sync = broken connections during failover. NAT tables aren’t shared by default — enable conntrack-sync.
- STP convergence on switch ports can delay failover. Use PortFast/edge ports.
- WAN failover ≠ link redundancy unless you have BGP with your own IP space. Two different WAN IPs mean two different NAT IPs.