Installing and Configuring Keepalived

Before you can set up load balancing by using Keepalived, install and configure the feature.

  1. Install the keepalived package on each server.

    Run the following command:

    sudo dnf install keepalived
  2. Edit /etc/keepalived/keepalived.conf to configure Keepalived on each server.

    See Keepalived Configuration Directives for more information.

  3. Validate the configuration file.
    sudo keepalived -t
  4. Enable IP forwarding on each server.

    Create /etc/sysctl.d/ip-forward.conf and add the following line:

    net.ipv4.ip_forward = 1
  5. Verify that the IP forwarding has been applied.

    Run the following command:

    sudo sysctl --system

    Confirm that the command output contains the following line:

    net.ipv4.ip_forward = 1
  6. Add firewall rules to accept VRRP communication by using the multicast IP address 224.0.0.18 and the VRRP protocol (112) on each network interface that Keepalived controls.

    For example, run the following commands on each server:

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

    Run the following command:

    sudo systemctl enable --now keepalived

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

    sudo systemctl reload keepalived