With the increasing need for Five 9 continuity and the advent of virtualization, High Availability (HA) is seen more in the IT community as a necessity instead of a luxury.
SuSE is the choice distribution for HA-Linux (Heartbeat) binaries and is included with SLES 10.
This article describes the process for setting up Apache in a passive/active cluster using Heartbeat. It is assumed that there is a common disk device for the web server.
The cluster consists of two SLES servers running Heartbeat and Apache in a cold standby mode.
Server1 is the active and has a DNS name of server1.mydomain.com
Server2 is the standby and has a DNS name of server2.mydomain.com
The cluster is named hacluster1.mydomain.com – Also the web server’s URL.
There are three main configuration files for HA (Heartbeat):
Lets’ take a look at each file what is required for our configuration.
There are three types of key methods for HA.
sha1 – SHA1 hash method
md5 – MD5 hash method
crc – CRC hash method – unsecured
The file looks like this:
auth 1 1 md5 AAAAB3NzaC1kc3MAAAEBALhTxBPKGEd1O2zYmDCVWtbaogOLZa+T
Auth 1 – determines with line number the key is located for use.
md5 is the method of encryption
This is the main configuration file for HA and determines how HA will act.
logfacility local0 # Logging node server1 server2 # List of cluster servers keepalive 1 # Send one heartbeat each second deadtime 10 # Declare node dead after 10 seconds bcast eth0 # Broadcast heartbeats on the eth0 interface ping 192.168.10.1 # Ping the default gateway to monitor ethernet # connectivity auto_failback no # Don't fail back to server1 automatically respawn hacluster /usr/lib/heartbeat/ipfail # Failover on network failures Refer to the man pages for more options.
This file describes how HA will manage resources. It is basically a collection of scripts to be executed by HA. We will only use Apache for our cluster. Here is the file:
server1 192.168.10.30 apache
We specify server1 (active) the IP address of the cluster and the service httpd (Apache).
HA also stops these resources in reverse order.
/sbin/chkconfig apache off
This will remove it from the runlevels and allow HA to start it.
Create a mount point for Apache to be accessed on either server. We’ll call it /ha
Create the subdirectories for your web site under /ha
Change the permissions for shared directories
chmod 775 /ha/srv/www
chmod 775 /ha/srv/www/htdocs
On each server, create a localname.html in /var/www/local, in this file put
<html> <head></head> <body> Welcome to SLES HA Cluster! The page you are viewing is being served from node server1.mydomain.com from cluster hacluster1.mydomain.com </body> </html>
and make sure you change the name of the server to the relevant server.
Create a symbolic link to the shared directories on both servers.
ln -s /ha/srv/www/htdocs /var/www/local
Create a symbolic link to the localname.html on both servers.
ln -s /var/www/local/localname.html /ha/srv/www/htdocs/index.html
We can test the setup and fail over by manually failing the primary. First, start the cluster. On the primary server and then on the backup server:
If there are any problems, or if you are just curious, look in /var/log/messages and /var/log/ha-log.
Open a browser and enter the URL of your cluster. hacluster1.mydomain.com/index.html
Note the node name in red for server1.mydomain.com
Ok. Let’s fail the node and see what happens. Don’t close your browser!
One server1, stop Heartbeat:
Now, Refresh your browser page.
Look at the server name! We failed over successfully… Sweet.
Now, more testing. The fail back. Restart the Heartbeat service on the primary and it should stop the service automatically on the backup, server2.
Refresh your browser page one more time.
Server1 is now back in control.
The fail over from the primary to the backup should occur in less than a minute depending on you Apache configurations.
This is just a small example of what resources can be maintained in a High Availability setup using Heartbeat. The main component for this to work in ensuring a homogeneous environment for both nodes.