The heartbeat+ldirectord solution

The ldirectord (Linux Director Daemon) written by Jacob Rief is a stand-alone daemon to monitor services of real servers, currently http and https service. It is simple to install and it works with the heartbeat code. The latest version of ldirectord can be found at the CVS repository of heartbeat. See 'perldoc ldirectord' for all the information about ldirectord. Thank Jacob Rief for writing this great program!

The advantages of ldirectord over mon are as follows:

  • The ldirectord is specially written for LVS monitoring.
    It reads configuration files like /etc/ha.d/xxx.cf, which contains all the information about the IPVS routing table configuration. When the ldirectord is up, the IPVS routing table will be configured properly. We can also save different virtual service configuration in multiple configuration files, so that it is possible to modify parameters of some services without bringing down other services.
  • The ldirectored can be easily started and stopped by heartbeat.
    Put the ldirectord under the /etc/ha.d/resource.d/ directory, then we can add a line in the /etc/ha.d/haresources like:
        node1 IPaddr::10.0.0.3 ldirectord::www ldirectord::mail
    

Anyway, the ldirectord can also be started and stopped manually. We can also use it in our LVS clusters without the backup of load balancer.

Configuation example

Taking the example introduced in the heartbeat+mon+coda solution, we can configure the /etc/ha.d/www.cf as follows:

#
# The /etc/ha.d/www.cf for ldirectord
#

# the number of second until a real server is declared dead
timeout = 10

# the number of second between server checks
checkinterval = 10

#
# virtual = x.y.z.w:p
#     protocol = tcp|udp
#     scheduler = rr|wrr|lc|wlc
#     real = x.y.z.w:p gate|masq|ipip [weight]
#     ...
#

virtual = 10.0.0.3:80
     protocol = tcp
     scheduler = wlc
     real = 192.168.0.1:80 gate 5
     real = 192.168.0.2:80 gate 5
     request = "/.testpage"
     receive = "test page"

The /etc/ha.d/haresources file is simple as follows:

    lvs1.domain.com IPaddr::10.0.0.3 ldirectord::www

We need to create the .testpage file at the DocumentRoot directory of each web server.

    echo "test page" > .testpage

Start the heartbeat daemons on the primary and the backup. If there is anything wrong, we may check the /var/log/ha-log and /var/log/ldirector.log respectively.