Apache – Configuring a HA Cluster On Centos
Node Base Builds
The two nodes used in the cluster were buit using a text based install of Centos with the following Package Groups selected :-
Applications
Editors
Text Based Internet
Development
Development Libraries
Development Tools
Servers
Server Configuration Tools
Web Server
Windows File Server
Base Tools
Administation Tools
System Tools
Clustering
Clustering
Installing heartbeat
Prior to building the cluster install the heartbeat packages with yum by running the following command :-
yum install heartbeat
Creating the configuration files
Copying the example files below to the /etc/ha.d directory on the two nodes
/usr/share/doc/heartbeat-2.1.3/authkeys to /etc/ha.d
/usr/share/doc/heartbeat-2.1.3/ha.cf to /etc/ha.d
/usr/share/doc/heartbeat-2.1.3/haresources to /etc/ha.d
Editing the authkeys file
Edit the file /etc/ha.d/authkeys and add the following lines to the end of the file :-
auth 2
2 sha1 test-ha
Save and exit the file and then change the permissions so the root user only can read / write the file by running chmod 600 authkeys
Editing the ha.cf file
Edit the file /etc/ha.d/ha.cf and add the following lines to the end of the file :-
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node {first cluster server node name}
node {second cluster server node name}
Save and exit the file
N.B. The two node names above can be found by running uname -n on both nodes
Editing the haresources file
Edit the file /etc/ha.d/haresources and add the following lines to the end of the file :-
{first cluster server node name} 172.16.4.82 httpd
Save and exit the file
Editing the httpd.conf file
Edit the file /etc/httpd/conf/httpd.conf and add the line below :-
Listen {Virtual IP Address to be used}:80
Save and exit the file
N.B. The IP address used in the Listen line is the virtual IP address which is to be used to access the clustered Apache web site and must NOT be one of the physical node addresses
Create a test index.html on each node
In order to test that heartbeat is configured correctly and working create a new index.html on each cluster node under the /var/www/html folder.
Ensure that the node name is referenced on the web page so that testing is easier to confirm by the name provided on the page.
Copying the configuration files to the second node
Once the files above have been created and modified copy the /etc/ha.d folder and it’s contents along with the /etc/httpd/conf/httpd.conf file to the second node.
Start heartbeat on each node
Once the files have been copied to the second node start the heartbeat service on the first node by running the command below :-
service heartbeat start
To check that heartbeat has also brought up httpd by going to the virtual IP address and confirming that you’re test web page is opened from the first node.
Next run the same command to start heartbeat on the second node and then stop the service on the first node by running the command below :-
service heartbeat stop
Refresh the web page and confirm that the web page has changed to the second nodes test page.
If both nodes deliver their web pages correctly restart the heartbeat service on the first node and confirm that the web page swaps back to the first node test page after a few minutes.