Saturday, August 14, 2010

How To configure a JBOSS Cluster


To accomplish failover and load balancing feature, either we can use a hardware based load balancer or apache with JK module.  Here I am going to explain how to configure JBOSS cluster using apache and JK Module.
We require two different servers running JBOSS Application Server.  We can install the apache http server either on any one JBOSS server or we can also have a different server running apache http server.
Make sure that the following applications packages are installed and configured on the apache httpd server.
  1. Apache httpd server 2.0.x
  2. Mod_JK apache module 1.2.26
Installation and configuration of Apache httpd server:
  1. Install apache httpd server using up2date or yum or download the packages and install manually.  We can also download the source code and compile the packages.  (Installation of Zend Core for Oracle software is a good idea as it installs apache http server with almost all the modules except JK Module).
  2. Verify that JK module is installed.  If the JK module is installed then you see mod_jk.so file in /etc/httpd/modules folder provided the http server is installed in /etc/httpd.
  3. Load the JK module in apache httpd server’s configuration file by adding the following lines to /etc/httpd/conf/httpd.conf file.                              
LoadModule jk_module modules/mod_jk.so
4.    Append the following lines to the end of the /etc/httpd/conf/httpd.conf file.
include conf/modjk.conf
5.   Create a file named /etc/httpd/conf/modjk.conf and add the following contents:
JkLogFile logs/modjk.log
JkLogLevel info
JkWorkersFile conf/jkworkers.properties
JkMountFile conf/jkmount.properties
JkMount jkstatus
Order deny,allow
Allow from all
6.   Create a file named /etc/httpd/conf/jkworkers.properties and add the following lines:
worker.list=jboss,jkstatus
# Entries for 1st node
worker.node1.type=ajp13
worker.node1.host=10.154.2.202 ## IP address of 1st node
worker.node1.port=8009
worker.node1.lbfactor=1
worker.node1.disabled=false
worker.node1.socket_timeout=10
worker.node1.connect_timeout=20000
# Entries for 2nd node
worker.node2.type=ajp13
worker.node2.host=10.154.2.186 ## IP address of 2nd node
worker.node2.port=8009
worker.node2.lbfactor=1
worker.node2.disabled=false
worker.node2.socket_timeout=10
worker.node2.connect_timeout=20000
#Load Balancer
worker.jboss.type=lb
worker.jboss.balance_workers=node1,node2
worker.jboss.sticky_session=true
worker.jboss.sticky_session_force=false
worker.jboss.method=R
worker.jboss.lock=P
worker.jkstatus.type=status
7.    Create the file /etc/httpd/conf/jkmount.properties and add the following contents:
/jmx-console*=jboss
/application/* = jboss ## Add your application url i.e. if you are accessing application ashttp://jbossserver:8080/myapp then add /myapp/*=jboss.
8.   Restart httpd server.
The next step is to configure the JBOSS Nodes.
1.   Copy server/all to server/nodex.
2.   To differentiate between the JBOSS server instances add the jvmroute attribute with the syntax jvmRoute=”nodeX” in the file $JBOSS_HOME/deploy/jboss-web.deployer/server.xml by making the following changes:
Locate the line which contains the following
Change it to the following
3.    Enable JK by editing $JBOSS_HOME/server/nodex/deploy/jboss-web.deployer/META-INF/jboss-service.xml file by making the following changes
Locate the line which contains the following
false
Change the attribute value to true as follows:
4.   Repeat the steps 1, 2 & 3 for all the nodes.  Replace nodex with appropriate node number i.e. node1, node2 etc.
5.   Restart jboss application server with appropriate profile i.e. node1, node2 etc
Deploying Web Applications:
Deploy all the applications in server/profile/farm folder.  Replace profile with the appropriate profile i.e. node1, node2 etc.  Once the application is deployed on any node in cluster, the cluster service will copy the war file to other nodes and automatically deploy the application on all the nodes.
Accessing the Web Applications:
The application can be accessed directly by accessing the apache http server url i.e. http://httpserver/application.  Replace httpserver with domainname or ip address of http server and application with the application you configured in jkmount.properties file. The additional port number is not required to access the Web application.  The JK module will automatically forward the request to specific port on JBOSS Application Server.