A common configuration for an HA server is simply to provide an IP address and a single service to be failed over. This example will be an active/passive configuration for the Apache web server.
logfacility daemon # Log to syslog as facility "daemon" node paul silas # List our cluster members keepalive 1 # Send one heartbeat each second deadtime 10 # Declare nodes dead after 10 seconds bcast eth0 eth1 # Broadcast heartbeats on eth0 and eth1 interfaces ping 1.2.3.254 # Ping our router to monitor ethernet connectivity auto_failback no # Don't fail back to paul automatically respawn hacluster /usr/lib/heartbeat/ipfail # Failover on network failures
See the ipfail page for more information on the respawn directive above.
In most cases, this file can be identical between the two machines.
paul 1.2.3.4 apache
The first word (paul) on the line represents the "preferred" host for the service. The remainder of the line is the list of resources (services) which are part of this ResourceGroup. In this example, the sole resource group consists of two resources: an IP address (IPaddr::1.2.3.4) and the Apache web server. Although Heartbeat can use resources which are simply init scripts from /etc/init.d, both of these ResourceAgents are located in /etc/ha.d/resource.d. In every case, this file must be identical on both machines.
/etc/ha.d/authkeys must be mode 600. See the section on GeneratingAuthkeysAutomatically for information how to generate good keys automatically.
auth 1 1 sha1 PutYourSuperSecretKeyHere
Except when changing keys, this file must be identical on the two machines.
To get Apache to bind to the correct IP addresses, you have to tell it which IP address it should bind to.
This is done by the Apache Listen directive. In httpd.cf, include this directive:
Listen 1.2.3.4:port-number
It is important that you not let Apache be started by init at boot time. If you do that, then both init and Heartbeat will "fight" for control of Apache, and it won't work. You have to let Heartbeat control all resources that you include in haresources. To disable Apache from starting at boot time, issue the following command on both paul and silas:
/sbin/chkconfig apache off
or if you're using the httpd service script instead of the apache script:
/sbin/chkconfig httpd off
For the purposes of this example, we assume that somehow the Apache configuration files, and the web site content is being "magically" maintained on both machines and are sufficiently similar that no one will complain when failovers occur between nodes. You can use rsync for this if that meets your needs. Alternatively, one can use shared disk or DRBD when they need to be truly identical to the millisecond.
Hidayatullah Shaikh's article on Linux-HA and Apache