Apache JBoss Integration

Overview

Integration is achieved using the Tomcat JSP engine.

There are JBoss versions available which are distributed with Tomcat as the JSP container.

These notes are based on JBoss version 3.2.6 and Apache 1.3

Install the mod_jk.so connector

http://jakarta.apache.org/tomcat/faq/connectors.html states mod_jk is great and should be used for production. It is getting fixes as needed (which is now rare).

Latest stable version as of writing is jk-1.2.8 - Source here - must be compiled on target platform. Binary versions are available for some platforms here

Debian Woody or Sarge, simply 'apt-get install libapache-mod-jk'. 'dpkg -L libapache-mod-jk' will list all install files. Good documentation is in /usr/share/doc/libapache-mod-jk/mod_jk-howto.html.

The instructions for building the connector from source are somewhat confusing. As far as I can tell, you only need to build mod_jk.so, which is described below in 'Native Build'.

Native Build

You need to make sure you've got apxs or apxs2 installed. This is required to create Apache library modules. In Mandrake 10.0 this is supplied with the apache2-devel package. In Debian Woody or Sarge 'apt-get install apache-dev'.

See file:///usr/local/src/jakarta-tomcat-connectors-1.2.8-src/jk/build/docs/install/apache2.html for a description of the parameters. In most situations the configure script can correctly guess settings.

  • cd /usr/local/src/jakarta-tomcat-connectors-1.2.8-src/jk/native

Mandrake 10.0

  • ./configure --with-java-home=${JAVA_HOME} --with-apxs=/usr/sbin/apxs2 --enable-jni

Debian Woody

  • ./configure --with-java-home=${JAVA_HOME} --with-apxs=/usr/bin/apxs --enable-jni

  • make

On Linux the library will be named modjk.so - modjk.dll on Windows. It needs to be installed in the Apache modules directory. On Mandrake 10.0this is /usr/lib/apache2 (with a symbolic link from /etc/httpd/2.0/modules). On Debian Woody modules are in /usr/lib/apache/1.3.

Setup Apache

httpd.conf

Add the folllowing at the end of httpd.conf on Mandrake 10.0 - /etc/httpd/conf/commonhttpd.conf

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

Add the following at the end of httpd.conf on Debian Sarge - /etc/apache/httpd.conf

<IfModule mod_jk.c>
JkWorkersFile /etc/tomcat/jk/workers.properties
Include /var/lib/tomcat/conf/mod_jk.conf
</IfModule>

mod-jk.conf

Create mod-jk.conf in APACHE_HOME/conf as follows.

Mandrake 10.0 mod-jk.conf

# /etc/httdp/conf/addon-modules/mod-jk.conf.

# 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/addon-modules/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
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories

# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"

# Amend appropriately to forward all requests for /myapp/ to Tomcat
JkMount /myapp/* loadbalancer

Debian Woody mod_jk.conf

#/var/lib/tomcat/conf/mod_jk.conf

# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module /usr/lib/apache/1.3/mod_jk.so

# Where to find workers.properties
JkWorkersFile /etc/tomcat/jk/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
# Debian Woody mod_jk doesn't support ForwardDirectories
# JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkOptions +ForwardKeySize +ForwardURICompat

# JkRequestLogFormat - Debian Woody mod_jk doesn't support JkRequestLogFormat
#JkRequestLogFormat "%w %V %T"

# Amend appropriately to forward all requests for /myapp/ to Tomcat
JkMount /myapp/* loadbalancer

workers.properties

Debain Woody installs a template for workers.properties in /etc/tomcat/jk - (Debian Sarge doesn't appear to) - The file includes comments describing the options. Modify it to conform to that described below.

Create a workers.properties file in the same directory as specified in mod-jk.conf as follows;

# Define Node1
worker.node1.port=8009
worker.node1.host=www.fdsd.co.uk
worker.node1.type=ajp13
worker.node1.lbfactor=1
#local_worker should be commented out to enable load-balancing. Otherwise, only fail-over is available.
worker.node1.local_worker=1
worker.node1.cachesize=10

# Define Node2
#worker.node2.port=8009
#worker.node2.host= node2.mydomain.com
#worker.node2.type=ajp13
#worker.node2.lbfactor=1
##worker.node2.local_worker=1
#worker.node2.cachesize=10

# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=node1
#worker.loadbalancer.balanced_workers=node1, node2
worker.loadbalancer.sticky_session=0
worker.loadbalancer.local_worker_only=1
worker.list=loadbalancer

Restart Apache

/etc/init.d/httpd restart

or

/etc/init.d/apache restart

Configure Tomcat

Edit /usr/local/jboss-3.2.6/server/default/deploy/jbossweb-tomcat50.sar/server.xml and find the <Engine> tag. Amend to include a 'jvmRoute' attribute as follows.

    &lt;Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1"&gt;

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

Finally, we need to tell Tomcat to add the jvmRoute value to its session cookies so that mod_jk can route incoming requests. Edit /usr/local/jboss-3.2.6/server/default/deploy/jbossweb-tomcat50.sar/META-INF/jboss-service.xml and locate the <attribute name="UseJK"> element and change it's value to true.

<attribute name="UseJK">true</attribute>

Misc notes

  • jboss 3.0.8 uses tomcat 4.1.24

  • jboss 3.2.6 uses tomcat 5.0.28

Firewall

Shorewall

I use Shorewall to maintain a tight firewall.

I needed to add the following entries to /etc/shorewall/rules to allow JBoss 3.2.6 to run without error. They relate to the multicast protocol.

ACCEPT   fw     net:228.1.2.3   udp 45566
ACCEPT   fw     net:230.1.2.3   udp 45577
ACCEPT   fw     net:230.0.0.4   udp 1102
ACCEPT   fw     net:224.0.0.22  2
ACCEPT   net        fw:228.1.2.3    udp 45566
ACCEPT   net        fw:230.1.2.3    udp 45577
ACCEPT   net        fw:230.0.0.4    udp 1102

Resources

-- Frank Dean - 10 Feb 2005

Related Topics: ApacheHints