In general when people think about running a load balancer in front of a Java based application server it usually is Tomcat. This article describes how you can use Glassfish instead. It will also enable you to have automatic fail-over.
Requirements- Apache 2.2.x
- mod_proxy
- mod_rewrite
- Glassfish 2 ur2 +
Add the following to make Apache load balance to your Glassfish cluster:
RewriteEngine On
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location /balancer-manager>
SetHandler balancer-manager
</Location>
<Proxy balancer://mycluster>
BalancerMember http://10.1.1.2:38080 route=w1
BalancerMember http://10.1.1.3:38080 route=w2
BalancerMember http://10.1.1.4:38080 route=w3
</Proxy>
<Location /clusterjsp>
Order allow,deny
Allow from all
</Location>
ProxyPass /clusterjsp balancer://mycluster/clusterjsp lbmethod=byrequests
And for Glassfish you need to set up a cluster. See the cluster article for more information on how to setup a cluster. Once you have done that please return to this article for the remaining steps.
You now have both Apache and the cluster configured so it is
time to check if the load-balancer is online. Browse to
http://localhost/balancer-manager (where localhost is your
Apache server) and verify if the load-balancer sees the 3
workers and if the routes are set. Now the last remaining step
is to deploy a clusterable application.
The Glassfish distribution contains an example application that
you can deploy on a cluster. See
$GLASSFISH_ROOT/samples/quickstart/clusterjsp.
Go to the administration console of the administration server
and select your cluster. Click on the Applications tab and
click on Deploy, select the clusterjsp.ear file
that you found in the Glassfish samples and make sure
Availability is checked (this is for the fail-over). Then click
OK. Then browse to http://localhost/clusterjsp and
see your work in action!
You now are using Apache load-balancing, mod_proxy with a Glassfish cluster together. Please send comments, suggestions and any feedback to sales@manorrock.com.
(Glassfish 2)