Setting up Apache Web Server and Tomcat Application Server for load balancing using mod_proxy_balancer.
This example uses mod_proxy_balancer as the load balancer. This configuration is useful for applications that are stateless and therefore do not require clustering or sticky-sessions. For more information, you can also check the page:
http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html
The example also uses ERS Apache 2.2, but the configuration is the same except for directory paths using Apache 2.2.
First of all, you will need to load the mod_proxy_balancer module. If you also want to use the Balancer Manager, make sure mod_status is being loaded as well.
LoadModule status_module "/opt/ers40jk/apache2.2/modules/standard/mod_status.so" LoadModule proxy_balancer_module "/opt/ers40jk/apache2.2/modules/standard/mod_proxy_balancer.so"
Later in the config file, add something like the following to configure the balancer:
<IfModule mod_proxy_balancer.c> <Location "/balancer-manager"> SetHandler balancer-manager Order deny,allow Deny from all # Allow from local subnet only Allow from 192.168.0 </Location> <Proxy balancer://localhost> BalancerMember http://localhost:8280/ loadfactor=1 BalancerMember http://localhost:8380/ loadfactor=2 </Proxy> ProxyPass /lbtest balancer://localhost/lbtest/ </IfModule>
Note that this configuration limits the balancer-manager to clients with IP addresses that start with 192.168.0. You'll probably need to modify this as appropriate for your environment.
This example is setup for round robin load balancing where the second BalanceMember processes 2 of every 3 requests. You can adjust this and also the load balancing method based on your needs. Some different load balancing methods mentioned in the doc are byrequests, bytraffic and bybusyness. Additional properties like these can be set using the ProxySet directive as described at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
To test this, setup the following directory structure in each of your Tomcat instances (listening for HTTP traffic on ports 8280 and 8380 respectively):
linwin01-516> ls -R webapps/l*
webapps/lbtest:
index.html
Note: Be sure to make the index.html files unique to each Tomcat instance and directory so you can see the load balancer working for consecutive requests.
Popular Links
Recent Comments