Load Balancing your JBoss AS 5 cluster with Apache 2 and AJP
Most of this information comes from this page:
http://wiki.jboss.org/wiki/UsingMod_proxyWithJBoss
Make sure that at least following modules are loaded (uncomment this in httpd.conf)
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
Add those lines (for the balancer) in APACHE_HOME/conf/httpd.conf (replace the node information with your node information, as many as are in this cluster:
Order deny,allow
Allow from all
BalancerMember ajp://node1.mycluster.lan:8009/ route=node1 timeout=15
BalancerMember ajp://node2.mycluster.lan:8109/ route=node2 timeout=15
ProxySet stickysession=JSESSIONID
## to test session replication, comment out below
ProxySet lbmethod=bytraffic
</Proxy>
You'll need to add a proxypass, or a rewrite, if you prefer. I like a combination of both (you'll need mod_rewrite for this, but it allows apache to serve static content itself, and only bother jboss when it needs processing (CFML here; change .cfm to .jsp for jsp, etc.). Here is a virtual host configuration:
ServerName your.domain.name
DocumentRoot /path/to/static/content/
## log locations and whatnot omitted
# jack throughput up a bit in this case (caveats)
ProxyIOBufferSize 19000
LimitRequestFieldsize 18000
ProxyRequests Off
# our rewrite conditions
RewriteEngine on
RewriteCond %{REQUEST_fileNAME} !^\/myapplication
RewriteRule ^\/(.+)\.cfm(.+)? /myapplication/$1.cfm$2 [PT,QSA,L]
<Location /myapplication>
ProxyPass balancer://mycluster/myapplication/
ProxyPassReverseCookiePath /myapplication /
</Location>
</VirtualHost>
You may want to verify that JSESSIONID is being set as a cookie at this point-- if not, you may need to remove/change the ProxyPassReverseCookiePath attribute of the location directive (JBoss defaults to the application context name for the cookie path now).
Assuming you would like to load balance by server load or by server traffic, and/or want jboss to be able to do sticky sessions, and you followed my instructions for clustering JBoss 5, you won't need to add this to each of your jbossweb.sar/server.xml files (replacing the node1 with the node name for each nodes's server.xml file):
</Engine>
I guess I should go into the sticky sessions bit, here: There are many ways to set up your load balancing. You can replicate your sessions across servers (JBoss has a nice way of doing this through a database, be sure you're not using the HSQL db in production, as the docs say), or use sticky sessions (repeat requests go to the same node), or a combination.
You can do round robin, which basically just sequentially hands requests to each node (request 1 to node 1, request 2 to node 2, ect.), or you can do it by weight, where you shunt more traffic to the beefier servers.
A lot depends on what you're after, and what you have to work with, etc.
Without session replicating, your clients will lose any session information if a node goes down (assuming you're using the bytraffic lbmethod). Meaning they're logged out of that nifty webapp you are trying to provide five nines uptime (or whatever) for.
There is overhead associated with keeping the session for each client stored, essentially, on all the nodes.
There are a lot of ways to mitigate that overhead tho, so you should be able to provide at least one or two failovers before losing anyone's session (see info on "buddies" and whatnot (basically "cell" replicator groups)).
I could go on for a long time, but it's late, and this is enough for now, I figure.
Peace.

There are no comments for this entry.
[Add Comment] [Subscribe to Comments]