Board index Linux Apache

Moderator: chandranjoy

Setting up Heartbeat for Apache High Availability on Linux

Postby chandranjoy » Thu Dec 16, 2010 7:49 pm

Setting up Heartbeat for Apache High Availability on CentOS/RedHat:
Cluster Configuration
The cluster consists of two Linux servers running Heartbeat and Apache in a cold standby mode.
Image

Requirements:
Two Linux servers with NIC

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.

Configure Heartbeat

There are three main configuration files for HA (Heartbeat):

/etc/ha.d/authkeys
/etc/ha.d/ha.cf
/etc/ha.d/haresources


Lets' take a look at each file what is required for our configuration.

/etc/ha.d/authkeys


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


NOTE: This file must be identical on both servers.
/etc/ha.d/ha.cf


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.




NOTE: This file must be identical on both servers
/etc/ha.d/haresouces


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.

NOTE: This file must be identical on both servers.
Gotcha: Remove Apache from system boot on both servers, otherwise HA will conflict with /etc/init.d. To remove Apache from startup, run the following command as root.

/sbin/chkconfig apache off

This will remove it from the runlevels and allow HA to start it.

Configure Apache


Create a mount point for Apache to be accessed on either server. We'll call it /ha
Create the sub-directories for your web site under /ha
mkdir /ha/srv
mkdir /ha/srv/www
mkdir /ha/srv/www/htdocs


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/html, 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


Testing


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:

/etc/rc.d/init.d/heartbeat start


If there are any problems, or if you are just curious, look in /var/log/messages and /var/log/ha-log.
Image
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:

/etc/rc.d/init.d/heartbeat stop

Now, Refresh your browser page.

Open a browser and enter the URL of your cluster. hacluster1.mydomain.com/index.html

Image

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.

Conclusion
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.

References:
http://www.novell.com/communities/node/ ... ty-sles-10

Heartbeat(High Availability) with 2 Web nodes and 2 Load balancer's:
http://www.ibm.com/developerworks/library/l-halinux/

Cheers :)
chandranjoy
Site Admin
 
Posts: 283
Joined: Fri Oct 23, 2009 11:19 pm

Return to Apache

Who is online

Users browsing this forum: No registered users and 1 guest


cron