Monday, October 25, 2010

configure Jboss and Apache in cluster mode....

I have done some techniqal R & D on Apache and JBoss in clustering mode.

System Requirement :

Operating System :

RHEL 5.4 in cluster mode. both have same configuration.
Jboss Application Server V4
Apache Server

I'll give steps how to implement JBOSS and Apache(cluster mode) in RHEL cluster mode.


--->Install JBoss as follows :

step 1:go to the directory where the JBoss installer zip file (jboss-as-distribution-6.0.0.20100429-M3.zip) is situated
$ mkdir jbossinstallationdir
$ cd jbossinstallationdir
jar -xvf jboss-4.2.2.GA.zip

--->ask system admin to install linux OS completely so that Apache is also installed with it


--->download apache-tomcat connectors for jboss integration with apache


--->install the mod_jk.so as below :

Step 1:
Change to the connector installation directory> cd $CONNECTOR_HOME/jk/native


Step 2:
Run the build command> ./buildconf.sh


Step 3:
Run the configure command to link it to apache> ./configure --with-apxs=/usr/local/apache/bin/apxs


Step 4:
Make the package> make


Step 5:
Install the package> make install

Step 6:
verify if the mod_jk.so has been installed in the Apache modules directory /usr/lib/httpd/modules



--->configure Apache with mod_jk.so


step 1 :Add this line at the very bottom in /etc/httpd/conf :

# Include mod_jk configuration file
Include conf/mod-jk.conf



Step 2: Create the modjk config



Under /etc/httpd/conf, create mod-jk.conf and populate it as follows:


# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile conf/workers.properties

# Where to put jk logs
JkLogFile logs/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel info

# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"

# JkOptions indicates to send SSK KEY SIZE
# Notes:
# 1) Changed from +ForwardURICompat.
# 2) For mod_rewrite compatibility, use +ForwardURIProxy (default since 1.2.24)
# See http://tomcat.apache.org/security-jk.html
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Mount your applications
JkMount /__application__/* loadbalancer
# Let Apache serve the images
JkUnMount /__application__/images/* loadbalancer

# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/uriworkermap.properties

# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
# Note: Replaced JkShmFile logs/jk.shm due to SELinux issues. Refer to
# https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=225452
JkShmFile run/jk.shm

# Add jkstatus for managing runtime data

JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1




Note - mod_jk is ready to forward requests to JBoss instances. We need now to setup the workers



Step 3: Configuring workers



Under /etc/httpd/conf, create workers.properties and populate it as follows:

# Define list of workers that will be used
# for mapping requests
# The configuration directives are valid
# for the mod_jk version 1.2.18 and later
#
worker.list=loadbalancer,status


# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=node1.mydomain.com
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.prepost_timeout=10000 #Not required if using ping_mode=A
worker.node1.connect_timeout=10000 #Not required if using ping_mode=A
worker.node1.ping_mode=A #As of mod_jk 1.2.27
# worker.node1.connection_pool_size=10 (1)

# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host= node2.mydomain.com
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.prepost_timeout=10000 #Not required if using ping_mode=A
worker.node2.connect_timeout=10000 #Not required if using ping_mode=A
worker.node2.ping_mode=A #As of mod_jk 1.2.27
# worker.node1.connection_pool_size=10 (1)

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2

# Status worker for managing load balancer
worker.status.type=status



Important Note : Replace vales of worker.node1.host and worker.node2.host with actual server node hostname or ip-addresses.

Step 4 :copy workers.properties.minimal to /etc/httpd/conf

Note - This file contains the workers names

Step 5: Create the URI to worker map file



Create a uriworkermap.properties file in the /etc/httpd/conf directory. This file should contain the URL mappings you want Apache to forward to Tomcat. The format of the file is /url=worker_name. To get things started, paste this example into the file you created:

# Simple worker configuration file
#

# Mount the Servlet context to the ajp13 worker
/jmx-console=loadbalancer
/jmx-console/*=loadbalancer
/web-console=loadbalancer
/web-console/*=loadbalancer
/myapp/*=loadbalancer
!/myapp/images/*=loadbalancer
/admin/*=wlb
/manager/*=wlb
/jsp-examples/*=wlb
/servlets-examples/*=wlb
/examples/*=wlb

This will configure mod_jk to forward requests for the /jmx-console, /web-console and /myapp contexts to JBoss Web. The '!' at the beginning of the last line results in the URLs for the images dir in the myapp context not being forwarded. Instead httpd will handle them directly (which means they must be available on the httpd server).



Step 6: Restart Apache



Step 7:

Note : In node1 and node2 , do the following

* In JBoss 5, it's $JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml


(In the examples above, replace /all/ with the name of the AS configuration you are running.)




Locate the element and add an attribute jvmRoute:


.


The jvmRoute attribute value must match the name specified in workers.properties.



In the server.xml file, make sure that the AJP 1.3 Connector is uncommented, e.g.:




emptySessionPath="true" enableLookups="false" redirectPort="8443"
protocol="AJP/1.3" connectionTimeout="600000" maxThreads="200"/>

step 8 :Go to $JBOSS_HOME/server/all/deploy/jboss-web.deployer/META-INF/jboss-service.xml file (replace /all with your own server name). Locate the element with a name of UseJK, and set its value to true:

true

Step 10: Restart JBoss AS.



Step 11: Access the JBoss AS web-console through Apache by browsing to http://localhost/web-console and you should see the JBoss web console page.

No comments:

Post a Comment