This section shows how you can set up a two node, high-availability HTTP cluster with heartbeat on CentOS. Both nodes use the Apache web server to serve the same content.
Pre-Configuration Requirements
1. Assign hostname cluster1 to primary node with IP address 192.168.1.4 to eth0.
2. Assign hostname cluster2 to slave node with IP address 192.168.1.5
Note: on cluster1
# uname -n
must return cluster1
On cluster2
# uname -n
must return cluster2
192.168.1.6 is the virtual IP address that will be used for our Apache webserver (i.e., Apache will listen on that address).
Configuration
Step 1. Download and install the heartbeat package. In our case we are using CentOS so we will install heartbeat with yum:
# yum install heartbeat
or download these packages:
heartbeat-2.08
heartbeat-pils-2.08
heartbeat-stonith-2.08
Step 2. Now we have to configure heartbeat on our two node cluster. We will deal with three files. These are:
authkeys
ha.cf
haresources
Step 3. Now moving to our configuration. But there is one more thing to do, that is to copy these files to the /etc/ha.d directory. In our case we copy these files as given below:
cp /usr/share/doc/heartbeat-2.1.2/authkeys /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/ha.cf /etc/ha.d/
cp /usr/share/doc/heartbeat-2.1.2/haresources /etc/ha.d/
Step 4. Now let's start configuring heartbeat.First we will deal with the authkeys file, we will use authentication method 2 (sha1). For this we will make changes in the authkeys file as below.
vi /etc/ha.d/authkeys
Then add the following lines:
auth 2
2 sha1 test-ha
Change the permission of the authkeys file:
chmod 600 /etc/ha.d/authkeys
Step 5. Moving to our second file (ha.cf) which is the most important. So edit the ha.cf file with vi:
vi /etc/ha.d/ha.cf
Add the following lines in the ha.cf file:
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node cluster1
node cluster2
Note: cluster1 and cluster2 is the output generated by
# uname -n
Step 6. The final piece of work in our configuration is to edit the haresources file. This file contains the information about resources which we want to highly enable. In our case we want the webserver (httpd) highly available:
# vi /etc/ha.d/haresources
Add the following line:
cluster1 192.168.1.6 httpd
Step 7. Copy the /etc/ha.d/ directory from cluster1 to cluster2:
# scp -r /etc/ha.d/ root@cluster2:/etc/
Step 8. As we want httpd highly enabled let's start configuring httpd:
# vi /etc/httpd/conf/httpd.conf
Add this line in httpd.conf:
Listen 192.168.1.6:80
Step 9. Copy the /etc/httpd/conf/httpd.conf file to cluster2:
# scp /etc/httpd/conf/httpd.conf root@cluster2:/etc/httpd/conf/
Step 10. Create the file index.html on both nodes (cluster1 & cluster2):
On cluster1:
echo "Cluster1 apache Web server Test Page " > /var/www/html/index.html
On Cluster2:
echo "cluster2 Apache test server Test page too" > /var/www/html/index.html
Step 11. Now start heartbeat on the primary cluster1 and slave cluster2:
# /etc/init.d/heartbeat start
Step 12. Open web-browser and type in the URL:
http://192.168.1.6
It will show “Cluster1 apache Web server Test Page”
Step 13. Now stop the hearbeat daemon on Cluster1:
# /etc/init.d/heartbeat stop
In your browser type in the URL http://192.168.1.6 and press enter.
It will show “cluster2 Apache test server Test page too”
Step 14. We don't need to create a virtual network interface and assign an IP address (192.168.1.6) to it. Heartbeat will do this for you, and start the service (httpd) itself. So don't worry about this.
Don't use the IP addresses 192.168.1.4 and 192.168.1.5 for services. These addresses are used by heartbeat for communication between Cluster1 and Cluster2. When any of them will be used for services/resources, it will disturb hearbeat and will not work.
0 comments:
Post a Comment