Apache – Clustering On Centos

Apache – Clustering On Centos

Introduction

This article provides details on how to implement Apache on to a Centos cluster to provide HA capability.

The infrastructure used for this article was two virtual machines running Centos 5.3 with clustering configured running on a Fedora Core 8 64-bit host running VMWare Server 1.0.8.

Pre-requisites

Centos Cluster configured
Shared disk resources

Adding an Apache Clustered Service

Editing the httpd.conf file

Edit the file /etc/httpd/conf/httpd.conf file, find the Listen line and change it to the virtual IP address to be used as shown below :-

Listen {virtual ip address}:80

Next find the DocumentRoot line and change it to the location on the shared storage to be used as shown below :-

DocumentRoot “/{shared disk resource mount/http-cluster/html”

Next find each instance of /var/www in the file and change them to point to /{shared disk resource mount/http-cluster/folder as shown in the examples below :-

Alias /icons/ “/{shared disk resource mount/http-cluster/icons/”

Save and exit the file once it has been modified
Copy the /etc/httpd/conf/httpd.conf file to the second node in the cluster

N.B. There are several references to /var/www in the file for icons, error, cgi-bin, etc which require changing

Create the contents on the shared disk

On the shared disk create the http-cluster folder as shown below where clusdisk is used as an example for the mount point for the shared disk :-

mkdir /clusdisk/http-cluster

Next copy the contents of the /var/www folder to the newly created folder by running the command shown below using clusdisk as an example for the mount point for the shared disk :-

cp -rv /var/www /clusdisk/http-cluster

Confirm that the http-cluster folder now contains the folders html, icons, error, cgi-bin, etc and their contents
Modify the permissions for the files in the folder by running the following commands where clusdisk is used as an example for the mount point for the shared disk :-

chown -R apache /clusdisk/http-cluster

chgrp -R apache /clusdisk/http-cluster

Add the new resources to the cluster

Open the cluster configuration tool on the first node by running system-config-cluster

Highlight the Resources branch in the left hand pane and then click on the Create a resource button at the bottom of the right hand pane.
Select IP Address from the drop down box
Configure the same IP address as configured in the httpd.conf file Listen line
Click on OK to create the resource

Add the apache script resource

Highlight the Resources branch in the left hand pane and then click on the Create a resource button at the bottom of the right hand pane.

Select Script from the drop down box
Give the resource a name for example Clustered-Apache
Set the File (with path) to /etc/rc.d/init.d/httpd
Click on OK to create the resource

Add the apache cluster service

Highlight the Services branch in the left hand pane and then click on the Create a service button at the bottom of the right hand pane.

When prompted enter the name for the service for example Apache-Cluster and then click on the OK button.

Select the Failover Domain configured from the Failover domains drop down box.
Next click on the Add a Shared Resource to the service button.
Select the File system resource being used to host the web site when prompted and click on OK to add it to the service
Add the IP Address and the script resources created above to the service and the click on Close to create the service.

Propagate the configuration to the other node

Once the new Clustered Apache service has been configured click on the File, Save button to save it locally

Next click on the Send to cluster button to synchronise the changes to the other node.

Start the service

Click on the Cluster Management tab
Highlight the new service in the bottom section of the tab and click on the Enable button