Apache Load Balancer
Apache Load Balancer
node01
Messaging Part 1 Instance 1 for
e.g.: 192.168.0.140
192.168.0.2
node02
Messaging Part 1 Instance 2 for
e.g.: 192.168.0.90
This guide 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.
-1-
Apache Load Balancer Configuration
Pre-Configuration Requirements
1) Assign hostname node01 to primary node with IP address Messaging Part1 Server
Instance 1 (For e.g.:192.168.0.90) to eth0.
2) Assign hostname node02 to slave node with IP address Messaging Part1 Server Instance 2
(For e.g.:192.168.0.140).
Note: on node01
uname -n
On node02
uname -n
192.168.0. 2 is the virtual IP address that will be used for our Apache web-server (i.e.,
Apache will listen on that address).
Configuration
1) Download and install the heartbeat package. In our case we are using CentOS so we will
install heartbeat with yum:
2) Now we have to configure heartbeat on our two node cluster. We will deal with three
files. These are:
authkeys
ha.cf
haresources
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/
-2-
Apache Load Balancer Configuration
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
auth 2
2 sha1 test-ha
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
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
initdead 120
bcast eth0
udpport 694
auto_failback on
node node01
node node02
-3-
Apache Load Balancer Configuration
uname -n
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
vi /etc/httpd/conf/httpd.conf
Listen 192.168.0.2:80
10) Create the file index.html on both nodes (node01 & node02):
On node01:
On node02:
11) Now start heartbeat on the primary node01 and slave node02:
/etc/init.d/heartbeat start
http://192.168.0.2
-4-
Apache Load Balancer Configuration
/etc/init.d/heartbeat stop
14) We don't need to create a virtual network interface and assign an IP address (192.168.0.2)
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 of Messaging Part1 Server Instance 1 and Instance 2 for
services. These addresses are used by heartbeat for communication between node01 and
node02. When any of them will be used for services/resources, it will disturb heartbeat
and will not work. Be careful!!!
Installing Apache2
The package httpd has some dependencies. So please install the below packages through
DVD1 before httpd package installation.
Insert DVD1-> Goto folder CentOS_5.5 -> CentOS and install packages by using below
command
and regarding the postgresql-libs package we need exactly the below mentioned version
which is available from packages list of DVD1 only.
rpm -e postgresql-libs-8.3.3-1PGDG.rhel5.x86_64.rpm
-5-
Apache Load Balancer Configuration
Note: For Load Balancer configuration there is no need to install Postgresql server from
the packages provided in DVD4.
Start Apache:
/etc/init.d/httpd start
#==================LoadBalancer================
# Declare the module for <IfModule directive> (remove this line on Apache 2.x)
# AddModule mod_jk.c
# Update this path to match your conf directory location (put workers.properties
next to httpd.conf)
JkWorkersFile conf/workers.properties
-6-
Apache Load Balancer Configuration
# Update this path to match your local state directory or logs directory
JkShmFile /var/log/httpd/mod_jk.shm
# Update this path to match your logs directory location (put mod_jk.log next to
access_log)
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info
#==============================================
<VirtualHost 192.168.0.2:80>
ErrorLog /var/log/httpd/error.log
ProxyRequests Off
ProxyVia Off
JkMount /* loadbalancer1
</VirtualHost>
3) workers.properties.
-7-
Apache Load Balancer Configuration
# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=IP Address of Messaging Part 1 Server Instance 1 For
eg:192.168.0.140
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.redirect=node2
# Load-balancing behaviour
#For ex1.cdacmumbai.in
worker.loadbalancer1.type=lb
worker.loadbalancer1.balance_workers=node1,node2
worker.loadbalancer1.sticky_session=1
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host= IP Address of Messaging Part 1 Server Instance 2 For
eg:192.168.0.90
worker.node2.type=ajp13
worker.node2.lbfactor=10
worker.node2.cachesize=10
#worker.node2.redirect=node3
4) In above workers.properties
worker.node1.host
& worker.node2.host point to the machine where gateway services are running i.e.
IP Address of Messaging Part 1 Server Instance 1 and Instance 2 .
worker.node1.port & worker.node2.port must point to the AJP port of jboss @ssdg
(default is 8009).
/etc/init.d/httpd restart
-8-