Wednesday, April 20, 2011

Apache server load balancing with Multiple Tomcat Clustering-


Apache server load balancing with Multiple Tomcat Clustering- :





Load Balancing -: Load balancer accept request from external client and forward them to one of the available Backend servers according to a scheduling algorithm.
We can use dedicated hardware and any load balancing software for load balancing
Mod_proxy_balancer- : Apache web server’s module of mod_proxy_balancer the apache module developed to provide to load balancing over a set of web server. Load balancer it can keep track of session
Sticky Session- A single user always deals with the same backend server.

Installation -:

Apache modules- Download from apache’s web site, mod_proxy module for load balancing

Windows-: Download mod_proxy modules and copy in modules directory.
Linux- Download mod_proxy modules and run following command for compile.

#./configure --enable-proxy --enable-proxy-balancer [run ./configure –h
# make
# make install

Configuration-:

Windows-: Enable following load modules in and add require modules in httpd.conf file

C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Now we can add following lines for proxy-balancer (Cluster name is domain.abc.net with two member)

ProxyRequests Off
ProxyPass / balancer://domain.abc.net/ lbmethod=byrequests stickysession=jsessionid nofailover=On maxattempts=15

ProxyPreserveHost On

BalancerMember http://192.168.10.10:84
BalancerMember http://192.168.100.10:85



Linux-

We need three servers one is load balancer and other two workers nodes
Http Server configuration file “/etc/httpd/conf/httpd.conf” add following lines

Include conf/extra/httpd-proxy-balancer.conf

Now create the httpd-proxy-balancer.conf file in the “/etc/httpd/conf/httpd.conf” and add the following lines.

ProxyRequests Off
ProxyPass / balancer://domain.abc.net/ lbmethod=byrequests stickysession=jsessionid nofailover=On maxattempts=15

ProxyPreserveHost On

BalancerMember http://192.168.10.10:84
BalancerMember http://192.168.100.10:85



Load balancing method-:

There are three type of load balancing method used in mod_prxy
Byrequests-:Weighted request count balancing
Bytraffic-: Weighted traffic byte count balancing
Bybusyiness-: Pending request balancing

Where method is one of the three listed before. Default is byrequests



BalancerMember http://192.168.10.10:84 loadfactor=4
BalancerMember http://192.168.100.10:85 loadfactor=6

A load factor will be applied member of the cluster, in order to define and sharing load balancing between members of cluster.

In the following example 40% of the requests will be forwarded to the first and reaming 60% will be forward to second cluster.



ProxyPass / balancer://domain.abc.net/ lbmethod=byrequests stickysession=jsessionid

SESSION_ID is the name of the variable at the application level storing the session identifier.