Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

keepalived

keepalived moves a virtual IP between servers with VRRP, so one address stays up when a server dies — classic HA for load balancers.

Niveau
DevSecOps-service
Groep
Netwerkdiensten
Root nodig
Ja
Pakket
keepalived

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

keepalived runs on two or more servers. With the VRRP protocol they elect a MASTER that holds the virtual IP (VIP); the others are BACKUP. If the master stops sending adverts (server down) or a track script fails (for example HAProxy died), a backup takes the VIP within seconds. Clients always use the VIP. It can also run IPVS load balancing.

Typical uses: two HAProxy nodes in front of web apps, or in front of the Kubernetes API (port 6443).

Zo schrijf je het

keepalived [-f FILE] [-t] [-D] [-n]
systemctl {start|reload|status} keepalived

Belangrijkste delen

Config parts

global_defs
Router ID, script security.
vrrp_script NAME { script … interval … }
Health check.
vrrp_instance NAME { … }
One VIP group.
state MASTER|BACKUP
Start role.
priority N
Higher wins (100 master, 90 backup).
virtual_router_id N
Same on all nodes of one group (1–255).
virtual_ipaddress { … }
The VIP(s).
authentication / unicast_peer
Simple auth / unicast instead of multicast.
track_script { NAME }
Lower priority when the check fails.

Opties 5

Meest gebruikt

Flags

-t, --config-test
Check the config and exit.
-f FILE
Config file.
-D
Detailed log.
-n
Stay in the foreground.
-l
Log to the console.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Install on both nodes

    dnf install -y keepalived haproxy
  2. 2Master node config

    cat /etc/keepalived/keepalived.conf
    global_defs {
        router_id lb1
        enable_script_security
        script_user root
    }
    vrrp_script chk_haproxy {
        script "/usr/bin/systemctl is-active --quiet haproxy"
        interval 2
        fall 2
        rise 2
    }
    vrrp_instance VI_1 {
        state MASTER
        interface eth0
        virtual_router_id 51
        priority 100
        advert_int 1
        unicast_src_ip 192.168.122.21
        unicast_peer { 192.168.122.22 }
        virtual_ipaddress { 192.168.122.20/24 }
        track_script { chk_haproxy }
    }
  3. 3Backup node: same file with these changes

    grep -E "router_id|state|priority|unicast" /etc/keepalived/keepalived.conf
        router_id lb2
        state BACKUP
        priority 90
        unicast_src_ip 192.168.122.22
        unicast_peer { 192.168.122.21 }
  4. 4Allow VRRP in the firewall

    firewall-cmd --permanent --add-rich-rule='rule protocol value="vrrp" accept' && firewall-cmd --reload
  5. 5Check and start

    keepalived -t -f /etc/keepalived/keepalived.conf
    systemctl enable --now keepalived
  6. 6Who has the VIP?

    ip -br addr show eth0
    eth0  UP  192.168.122.21/24 192.168.122.20/24
  7. 7Test a failover

    systemctl stop haproxy
    journalctl -u keepalived -n 5
    ip -br addr show eth0
  8. 8Watch VRRP traffic

    tcpdump -ni eth0 vrrp
  9. 9Allow binding to the VIP on the backup (HAProxy)

    sysctl -w net.ipv4.ip_nonlocal_bind=1
    echo "net.ipv4.ip_nonlocal_bind = 1" > /etc/sysctl.d/90-vip.conf
  10. 10Read the state changes

    journalctl -u keepalived | grep -E "MASTER|BACKUP|FAULT"

Let op

  • Use a different virtual_router_id per group on the same network, or groups fight.
  • In most clouds (Azure, AWS) VRRP/multicast and moving IPs do not work — use the cloud load balancer.
  • Two masters at once (split brain) happen when nodes cannot see each other; check the firewall.

Bestanden

/etc/keepalived/keepalived.conf
Configuration.

Tips om te onthouden

  • Use unicast peers in VMs and labs; multicast is often blocked.

Exitcodes

0Success (config OK).
1Error (config invalid).

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man 8 keepalived