Labels

Monday, June 18, 2012

How to Load Balancing – Apache / JBoss ?

Enviornment
OS: Linux Redhat
Load Balancer: Apache 2 (assuming it is in /usr/local/apache2)
App Server: JBoss 4x
What to do in Apache?
You need to install mod jk module in it, if not already present.
Look inside /usr/local/apache2/modules dir, if there is any file with name similar to mod_jk*.so
If not, download from:
http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/x86_64/mod_jk-1.2.31-httpd-2.2.x.so
And rename it to mod_jk.so and add to:
/usr/local/apache2/modules
Add workers.properties file to: /usr/local/apache2/conf
Contents of workers.properties file are:
worker.list=loadbalancer
#Worker 1
worker.worker1.type=ajp13
worker.worker1.host=IPAddressOfJBossServer1
worker.worker1.port=8109
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
#Worker 2
worker.worker2.type=ajp13
worker.worker2.host=IPAddressOfJBossServer2
worker.worker2.port=9109
worker.worker2.lbfactor=50
worker.worker2.cachesize=10
worker.worker2.cache_timeout=600
worker.worker2.socket_keepalive=1
worker.worker2.socket_timeout=300
#Load Balancer
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker1,worker2
worker.loadbalancer.sticky_session=1

What to do in JBoss?
We will need at least two JBoss installations. If both are on same machine, then their ports must be different, if they are on different machines, then ports can remain same ofcourse.
Usually there is nothing to do in JBoss, since all the necessary ports are pre-configured. But you can check nevertheless.
The main thing here is to know – what the JBoss JK Port is. This is configured in bindings xml file. By default the bindings file is this one:
[JBoss_Home]/docs/examples/binding-manager/Sample-Bindings.xml
Typically, if JBoss http port is 8180, JK Port is 8109 (i.e HTTPPort-71, that’s what the calculation usually is!!)
This JKPort is what we provide in workers.properties file mentioned before. Thats it.
Restart JBoss.
Restart Apache.

No comments:

Post a Comment