17.5 Installing and Configuring Keepalived

To install Keepalived:

  1. Install the keepalived package on each server:

    # yum install keepalived
  2. Edit /etc/keepalived/keepalived.conf to configure Keepalived on each server. See Section 17.5.1, “About the Keepalived Configuration File”.

  3. Enable IP forwarding:

    # echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
    # sysctl -p
    net.ipv4.ip_forward = 1
  4. Add firewall rules to allow VRRP communication using the multicast IP address 224.0.0.18 and the VRRP protocol (112) on each network interface that Keepalived will control, for example:

    # firewall-cmd --direct --permanent --add-rule ipv4 filter INPUT 0 \
      --in-interface enp0s8 --destination 224.0.0.18 --protocol vrrp -j ACCEPT
    success
    # firewall-cmd --direct --permanent --add-rule ipv4 filter OUTPUT 0 \
      --out-interface enp0s8 --destination 224.0.0.18 --protocol vrrp -j ACCEPT
    success
    # firewall-cmd --reload
    success
  5. Enable and start the keepalived service on each server:

    # systemctl enable keepalived
    ln -s '/usr/lib/systemd/system/keepalived.service' \
      '/etc/systemd/system/multi-user.target.wants/keepalived.service'
    # systemctl start keepalived

    If you change the Keepalived configuration, reload the keepalived service:

    # systemctl reload keepalived