Heartbeat-driven Apache HA Setup and Production Maintenance Guide

Practical Example: Highly Available Apache Web Service with Heartbeat

1. Lab Environment

Two RHEL/CentOS hosts:

  • node-a – 192.168.1.130
  • node-b – 192.168.1.129

A floating virtual IP (VIP) 192.168.1.131/24 will be managed by Heartbeat and bound to whichever node is active.

2. Install Apache on Both Nodes

sudo yum install -y httpd

3. Prepare the Resource Script

Heartbeat expects a start/stop script in /etc/ha.d/resource.d/. Copy the stock init script and make it executable:

sudo cp /etc/init.d/httpd /etc/ha.d/resource.d/
sudo chmod +x /etc/ha.d/resource.d/httpd

The script must:

  • Reside in /etc/ha.d/resource.d/ or /etc/init.d/.
  • Accept start and stop arguments.
  • Have the same base name as the resource listed in haresources.

4. Disable OS-level Auto-start

sudo systemctl disable httpd
sudo systemctl stop  httpd

5. Configure haresources on Both Nodes

# /etc/ha.d/haresources
node-a IPaddr::192.168.1.131/24/eth0:1 httpd

The line means:

  • node-a is the preferred primary.
  • 192.168.1.131/24 will be plumbed on eth0:1.
  • httpd will be of the resourcce script copied earlier.

Heartbeat Deployment Patterns

Pattern Description Typical Use Case
VIP-only Heartbeat only migrates the VIP; services are started by systemd or a supervisor. Stateless web servers, reverse proxies.
VIP + Service Heartbeat moves both the VIP and the service (start/stop via resource script). Stateful DBs, NFS, DRBD-backed storage.

Guardian Daemon: If you choose the VIP-only pattern for Apache, add a lightweight watchdog that probes curl -f http://localhost/ >/dev/null. On failure, stop Heartbeat to force a failover.

Heartbeat vs. Keepalived

  • Web / DB / Proxy tiers: Both tools can handle VIP failover.
  • LVS directors: Keepalived natively integrates ipvsadm and real-server health checks. Heartbeat can call a custom script that wraps ipvsadm, but you lose built-in RS monitoring unless you add ldirectord.
  • DRBD clusters: Heartbeat ships with ready-made drbddisk and Filesystem resource agents, making it the usual choice for MySQL dual-primary or NFS-over-DRBD setups.

Production Maintenance Workflow

  1. Version Control: Keep /etc/ha.d/ under SVN/Git. Always diff before pushing.

  2. Graceful Transition:

    # On the active node
    sudo /usr/lib64/heartbeat/hb_standby
    # Verify the standby has taken over
    # Edit configs
    sudo vim /etc/ha.d/haresources
    sudo /usr/lib64/heartbeat/hb_takeover
    
  3. Validation Script: After every takeover, run:

    #!/bin/bash
    for vip in 192.168.1.131 192.168.1.132; do
        ip addr show | grep -q $vip || exit 1
    done
    curl -sf http://192.168.1.131/health || exit 1
    

    Attach the script to Heartbeat’s start action for automated smoke tests.

  4. Adding a New VIP:

    1. Create the alias on the active node to confirm reachability.
    2. Edit haresources to include the new VIP.
    3. Restart Heartbeat during a low-traffic window.
    4. Remove the temporary alias once Heartbeat owns the new IP.

Tags: Heartbeat apache high-availability drbd Keepalived

Posted on Sun, 17 May 2026 16:29:21 +0000 by saqibb