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 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/
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/
JkMountFile conf/
JkMount jkstatus
Order deny,allow
Allow from all
6.   Create a file named /etc/httpd/conf/ and add the following lines:
# Entries for 1st node
worker.node1.type=ajp13 ## IP address of 1st node
# Entries for 2nd node
worker.node2.type=ajp13 ## IP address of 2nd node
#Load Balancer
7.    Create the file /etc/httpd/conf/ and add the following contents:
/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
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 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.