Blog Archive

iSeries connect Tomcat to Apache using mod_jk module (QZTCJK.SRVPGM)

This document explains how to connect Tomcat to the popular open source web server, Apache. There is actually two version of Apache, 1.3 and 2.0 and both can be used with mod_jk, the Tomcat redirector module. 

Please Note: You can use this document as a reference to connect Apache and Tomcat on any other machine such as window, unix, etc. All you need to change is one line of code LoadModule mod_jk with right module for your system such as mod_jk.so (unix) or mod_jk.dll (Windows).

The ajp12 protocol is only available in Tomcat 3.2.x and 3.3.x. The ajp12 has been deprecated with Tomcat 3.3.x and you should use instead ajp13 which is the only ajp protocol known by Tomcat 4.0.x, 4.1.x and 5 and above.

mod_jk requires two entities:


  • mod_jk.xxx - The Apache module, depending on your operating system, it will be mod_jk.so, mod_jk.dll, mod_jk,nlm or or QZTCJK.SRVPGM (for iSeries) .
  • workers.properties - A file that describes the host(s) and port(s) used by the workers (Tomcat processes).

Also as with other Apache modules, mod_jk should be first installed on the modules directory of your Apache webserver, ie : /usr/lib/apache and you should update your httpd.conf file.

Follow these steps:

1) Open Apache config file httpd.conf (path to the file {apache_home}/conf/httpd.conf)
Add LoadModule jk_module /QSYS.LIB/QHTTPSVR.LIB/QZTCJK.SRVPGM

The modules mod_jk provides five directives used to communicate with the ASF Tomcat Servlet Engine. These directives go into the HTTP Server (powered by Apache) server configuration file (httpd.conf). Any mod_jk directive usage must be preceded by loading the Service Program that supports mod_jk. The following LoadModule must be in the configuration file prior to the use of any mod_jk directives.
LoadModule mod_jk /QSYS.LIB/QHTTPSVR.LIB/QZTCJK.SRVPGM

Directives
  • JkAsfTomcat
  • JkLogFile
  • JkLogLevel
  • JkMount
  • JkMountCopy
  • JkWorkersFile

2) Add the mod_jk directives for connecting to Tomcat
JkWorkersFile {apache_home}/conf/workers.properties
JkLogFile     {apache_home}/logs/jk.log
JkLogLevel    debug
JKMount       /examples/servlet/* ajp13w
JKMount       /examples/images/* ajp13w
JKMount       /{servlet_application}/* ajp13w 

3) Define the workers.properties file in the path mentioned above
worker.list=ajp13w               
worker.ajp13w.type=ajp13         
worker.ajp13w.host=localhost     
worker.ajp13w.port=8009   

In case you want to build your own jk_mod from source
  • Building mod_jk for Apache on iSeries/OS400

Since OS400 V4R5, iSeries (AS/400) has used Apache 2.0 as their primary web server, replacing the old IBM webserver. It's now possible to build mod_jk on iSeries thanks to the help of the IBM Rochester Labs which has provided information and patches to adapt mod_jk to OS400.

You should have at least Apache 2.0.39, a C Compiler and IFS. Apache 2.0.39 is provided with the most recent set of PTFs for the iSeries Apache server, which can be found at http://www.ibm.com/servers/eserver/iseries/software/http/

To configure mod_jk on iSeries use the CL source provided with the mod_jk source.

  • Get the latest mod_jk source and untar it on a Windows or Unix boxes
  • Create a directory in IFS, ie /home/apache
  • Send the whole jk source directory to iSeries directory via FTP.
Then go to the iSeries command line :
Create mod_jk library
===> CRTLIB MOD_JK TEXT('Apache mod_jk tomcat connector module')
Create service program source file
===> CRTSRCPF MOD_JK/QSRVSRC TEXT('Service program source file')
Create the CL build program source file
===> CRTSRCPF FILE(MOD_JK/QCLSRC) TEXT('Build program source file')
Edit the service program source file
===> STRSEU MOD_JK/QSRVSRC MOD_JK

In the edited file, specify that only jk_module should be exported :
Columns . . : 1 71 Edit MOD_JK/QSRVSRC
SEU==> MOD_JK
*************** Beginning of data *************************************
0001.00 STRPGMEXP PGMLVL(*CURRENT)
0002.00 EXPORT SYMBOL("jk_module")
0003.00 ENDPGMEXP
****************** End of data ****************************************

You could start to build all the modules of mod_jk :
Copy the CL build program source from IFS
===> CPYFRMSTMF FROMSTMF('/home/apache/jk/native/apache-2.0/bldjk.qclsrc') +
TOMBR('/QSYS.LIB/MOD_JK.LIB/QCLSRC.FILE/BLDJK.MBR') MBROPT(*REPLACE)
Build the CL build program
===> CRTCLPGM PGM(MOD_JK/BLDJK) SRCFILE(MOD_JK/QCLSRC) TEXT('Apache mod_jk build program')
Launch the build
===> CALL MOD_JK/BLDJK
If the build if successfull, copy the new mod_jk module
===> CRTDUPOBJ OBJ(MOD_JK) FROMLIB(MOD_JK) OBJTYPE(*SRVPGM) TOLIB(QHTTPSVR) NEWOBJ(MOD_JK)

Next, you should restart your Apache 2.0 server and enjoy this piece of OpenSource on iSeries.


More Reading Material below ...
Module mod_jk for HTTP Server (powered by Apache)
Apache JServ Protocol version 1.3 (ajp13) how to


3 comments :