الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

keepalived

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

المستوى
خدمة DevSecOps
المجموعة
خدمات الشبكة
يحتاج root
نعم
الحزمة
keepalived

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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).

طريقة الكتابة

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

الأجزاء الرئيسية

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.

الخيارات 5

الأكثر استخدامًا

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.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع 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"

انتبه

  • 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.

الملفات

/etc/keepalived/keepalived.conf
Configuration.

نصائح للحفظ

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

رموز الخروج

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man 8 keepalived