The Virtual Router Redundancy Protocol (VRRP) is a network protocol that provides for automatic assignment of available Internet Protocol (IP) routers to participating hosts. This ensures the high availability of the services that rely on HAPEE for load-balancing.

VRRP comprises two parts:

  • A software installed on each node of a VRRP cluster. It computes a weight based on its configuration and local health check results.
  • A network protocol used by each node of a VRRP cluster to exchange information about their status.

Understanding VRRP

In general, VRRP works as follows:

  • The node that has the highest weight is the master. The other nodes are slaves.
  • The master hosts the Virtual IP (VIP). It notifies the switches and the servers on the LAN through ARP packets.
  • The master emits a heartbeat packet every second. This packet contains its weight and goes out on a multicast IP address (
  • Each node can change its weight based on its configuration and health check results.

Failover triggers

The following events can trigger a failover:

  • The master node lowers its weight below one of the slave nodes due to a failed health check.
  • A slave node is configured with a weight larger than the current master node.
  • The master stops emitting its heartbeat packet.

VRRP terminology

Term Definition
nodes Members of a VRRP cluster
master The node hosting the VIP (Virtual IP addresses)
slave A node in standby, listening on
VIP (also called Virtual IP) The IP address where the load-balancer listens for incoming traffic
failover The process when there is a new master node and the VIP moves from the old master node to the new one

Installing VRRP

For Debian/Ubuntu:

apt-get install hapee-1.6-vrrp

For Redhat/Centos:

yum install hapee-1.6-vrrp

Configuring VRRP

You configure VRRP using the configuration file at /etc/hapee-1.6/hapee-vrrp.cfg. This file is split into two main objects:

  • Health check script to define checks to perform and weight modulation. These checks must define the status of the local server and ensure that everything is ready.
  • VRRP instance to define the VIP and related configuration (VrID, weight, health check scripts, IPs, etc.)

Set parameters for VRRP health check scripts

The following parameters enable the local health checking scripts to alter the weight of local node in the VRRP cluster:

Name Argument type Description
script string Command to run; accepts pipes between multiple commands.
interval integer Interval (in seconds) between two checks
weight integer Points to add or remove to instance weight
fall integer Number of consecutive negative checks before considered as down
rise integer Number of consecutive positive checks before considered as up

The script below checks the status of the sshd daemon every 5 seconds. If the service is not available, then its weight is reduced by 4 points:

vrrp_script chk_sshd {
  script "pkill -0 sshd"          # pkill -0 is cheaper than pidof
  interval 5                      # check every 5 seconds
  weight -4                       # remove 4 points of prio if missing
  fall 2                          # check twice before setting down
  rise 1                          # check once before setting up

Create a VRRP instance

Set the following parameters to create a VRRP instance:

Name Argument type Description
vrrp_instance string Describes a new VRRP instance
interface string Interface managed by keepalived
state string State at startup until VRRP negotiation completes. Can be either MASTER or BACKUP
virtual_router_id integer VRRP instance identifier which must be common to all nodes of the same cluster. Its value ranges from 0 to 255.
priority integer Weight of local node in this VRRP instance
virtual_ip_address string List of virtual IP addresses to add or remove when the state changes to MASTER or BACKUP. All VRRP nodes in a cluster must own the same IP.
virtual_ip_address_excluded string Same as virtual_ip_address; but IPs are not announced in the VRRP heartbeat packet. It is used when more than 200 VIPs are in use
track_interface string Tracks interface status and updates priority accordingly
track_script string Runs the script and updates priority accordingly

Set the followingVRRP instance:

  • HAPEE MASTER on interface eth0
  • Cluster id 51
  • Priority of 101
  • 2 IP addresses that are not announced through theVRRP heartbeat packet
  • Local weight updated based on scripts chk_ssd and chk_lb
vrrp_instance vrrp_1 {
  interface eth0                  # or bond0 or whatever prod interface
  virtual_router_id 51            # use a distinct value for each instance
  priority 101                    # 101 on master, 100 on backup
  virtual_ipaddress_excluded {
             # your shared service IP address(es)
             # your shared service IP address(es)
  track_interface {
          eth0 weight -2          # interfaces to monitor
          # eth1 weight -2
  track_script {


The VRRP configuration must be exactly the same on all nodes of a cluster. However, the priority must be adapted to the role of the server MASTER or SLAVE.