×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

General e-Business discussion FAQ

Tomcat and Apache

Apache and Tomcat configuration on Win32 systems using the AJP connector (do not use WARP on Win32) by baden
Posted: 19 Apr 02

[!]

First off, I apologize for not posting this here earlier, but this document is searchable on Usenet/Google Forums.

Don't hesitate to email me with questions, comments, etc!!!

[!]

Configure Apache v1.3.23 and Tomcat 4.0.2 with the AJP Connector on Windows 2000

Please send me your feedback:  baden@pmcanada.com

March 2002

This installation will not work with Tomcat v4.0.1, as $CATALINA_HOME/server/lib/ tomcat-ajp.jar does not contain the files that create the global Apache directives (ie. LoadModule, JkLogFile).

Also, if you are thinking about using mod_webapp on a Win32 environment û donÆt:

[* ! *] Important note:  Using the mod_webApp connector under a Windows environment has proven to be flaky.  Specifically, an error like the following has been reported:
WebApp: Error 500
(File: pr_warp.c Line: 434)
(null)


More information on installing the AJP connector can be found at http:// jakarta.apache.org/tomcat/tomcat-4.0-doc/config/ajp.html

#########################
 Install mod_jk.dll in Apache
#########################

Locate and download the Win32 file mod_jk.dll - http://jakarta.apache.org/builds/ jakarta-tomcat/release/v3.3/bin/win32/i386/mod_jk.dll

You can also download the list of connectors from  http://cvs.apache.org/ snapshots/jakarta-tomcat-connectors/. ; You will have to build each connector you want to use.  For mod_jk, you would issue the following command:
+ MSDEV mod_jk.dsp /MAKE ALL

More information about this method can be found at http://atlassw1.phy.bnl.gov/ jakarta-tomcat/mod_jk-howto.html

Move mod_jk.dll to $APACHE_HOME/modules.


#########
server.xml
#########

If it is not already, uncomment the AJP connector section in $CATALINA_HOME/ conf/server.xml.  This section starts with ô<!-- Define an AJP 1.3 Connector on port 8009 -->ö.  The next lines should now read:
<Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
               port="8009" minProcessors="5" maxProcessors="75"
               acceptCount="10" debug="0"/>

Next we need to create a server listener to generate the Apache directives.  If you are not using virtual hosts, look somewhere around line 13 for the following:
+ <Server port="8005" shutdown="SHUTDOWN" debug="0">
Right under this, insert the following:
+ <Listener className="org.apache.ajp.tomcat4.config.ApacheConfig"  modJk= ô$APACHE_HOME./modules" />

If you are using virtual hosts, look for the following line at around line 216:
+ <Host name="localhost" debug="9" appBase="webapps" unpackWARs="true">
Right under this, insert the following:
+ <Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" append="true" modJk= ô$APACHE_HOME./modules/mod_jk.dllö  />

The modJk attribute sets the location path to mod_jk.dll.  Replace ô$APACHE_HOMEö with the explicit path.

It was found that when Tomcat 4.0.2 creates the LoadModule directive in  mod_jk.conf, it does not insert quotation marks around the path.  Thus, if you have spaces in your path, this will not work when you load Apache, adding the line:
+ Include "C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/conf/auto/ mod_jk.conf"
Will not work!

You can Add the directives directly to httpd.conf.


##########
httpd.conf
##########

Add the following after the LoadModule chunk, somewhere around line 197:
#====================    CUT   ==========================
#
# ###################     Load mod_jk  ###########################
#

<IfModule !mod_jk.c>
  LoadModule jk_module "C:/JAVADEV/Apache Group/Apache/modules/mod_jk.dll"
</IfModule>

JkWorkersFile "C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/conf/jk/ workers.properties"
JkLogFile "C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2/logs/jk_log.txt"

JkLogLevel debug
#====================    CUT   ==========================

A few lines below this should be the AddModule chunk.  Add the following in this chunk:
#====================    CUT   ==========================
#
# JK
#
AddModule mod_jk.c
#====================    CUT   ==========================


Next we need to tell Apache what to forward to Tomcat.  At around line 333, the ôDocumentRootö should be defined.  Add the following just below this:
#====================    CUT   ==========================
JKMount /servlet/* ajp13
JkMount /*.jsp ajp13
JkMount /examples/* ajp13
JkMount /manager/* ajp13
JkMount /tomcat-docs/* ajp13
JkMount /webdav/* ajp13
#====================    CUT   ==========================


I created a small example index: $CATALINA_HOME/webapps/examples/ index.html.

#====================    CUT   index.html ===================
<html>
<body bgcolor="d9d9d9">
<p>
<center><u><h1>Tomcat 4.0.2 - Examples</h1></u>
<hr>
<a href="jsp/index.html">JSP examples</a><p>
<a href="servlets/index.html">Servlet examples</a><p>
</center>

</body>
</html>
#====================    CUT   ==========================


#################
workers.properties
#################

If you execute $CATALINA_HOME/bin/startup.bat, you will see an error indicating that the workers.properties file cannot be found, but the mod_jk.conf will be created.

After doing this, open $CATALINA_HOME/conf, where two directories will be created,
$CATALINA_HOME/conf
----+auto
--------mod_jk.conf
----+jk
--------workers.properties

The jk directory is where the workers.properties file needs to be defined as follows:
#====================    CUT   ==========================
# Setup for Windows system
#
workers.catalina_home="C:/JAVADEV/Apache Group/Apache Tomcat 4.0.2"
workers.java_home="C:/JAVADEVA/jdk1.3.1_02"

# Linux uses fwd slashes
#ps=/

# Windows uses back slashes
ps=\


worker.list= ajp13

# Definition for Ajp13 worker
#
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
#====================    CUT   ==========================

The workers.catalina_home and workers.java_home paths should be set to your specific configuration.


Finally, as some documentation indicated, take off all your clothes, dance around your server and do the following:

Load Tomcat.
Load Apache.

Open your web browser and go to http://localhost û this should return an Apache page.
Go to http://localhost/examples/ and this should bring up the index.html created above.  Even create a *.jsp file (you can rename the index.html to this) and load it with http://localhost/examples/myjsp.jsp. ;

tomcat-docs/, webdav/ and manager/ should work just fine as well.



Load balancing

This documentation will be included soon ---- for now, visit http:// www.ubeans.com/tomcat/index.html for more information on how to load balance your server.

For load balancing, you must install more than one Tomcat server.  Each of the servers has an AJP connector listening on a different port.  For this example, the servers will be called tomcat1 and tomcat2.  tomcat1 and tomcat2Æs AJP13 connector will be listening on ports 11009 and 12009, respectively.

Create the workers.properties file exactly as detailed below
#====================    CUT   ==========================
#
# workers.properties
#

# In Windows, we use forward slashes:
ps=\

# list the workers by name

worker.list=tomcat1, tomcat2, loadbalancer

# ------------------------
# First tomcat server
# ------------------------
worker.tomcat1.port=11009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13

# Specify the size of the open connection cache.
#worker.tomcat1.cachesize

#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.tomcat1.lbfactor=100


# ------------------------
# Second tomcat server
# ------------------------
worker.tomcat2.port=12009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13

# Specify the size of the open connection cache.
#worker.tomcat2.cachesize

#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
#  ----> lbfactor must be > 0
#  ----> Low lbfactor means less work done by the worker.
worker.tomcat2.lbfactor=100


# ------------------------
# Load Balancer worker
# ------------------------

#
# The loadbalancer (type lb) worker performs weighted round-robin
# load balancing with sticky sessions.
# Note:
#  ----> If a worker dies, the load balancer will check its state
#        once in a while. Until then all work is redirected to peer
#        worker.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1, tomcat2

#
# END workers.properties
#
#====================    CUT   ==========================


Add the following to the system variables JAVA_HOME and CATALINA_HOME (respectively):
+ ; export JAVA_HOME
+ ; export CATALINA_HOME


##########
httpd.conf
##########

Next we need to tell Apache what to forward to Tomcat.  At around line 333, the ôDocumentRootö should be defined.  Add the following just below this:
#====================    CUT   ==========================
JKMount /servlet/* loadbalancer
JkMount /*.jsp loadbalancer
JkMount /examples/* loadbalancer
JkMount /manager/* loadbalancer
JkMount /tomcat-docs/* loadbalancer
JkMount /webdav/* loadbalancer
#====================    CUT   ==========================


#########
server.xml
#########

At or around line 100, replace:
<Engine name="Standalone" defaultHost="localhost" debug="0">
with:

<Engine jvmRoute="tomcat1" name="Standalone" defaultHost="localhost" debug="0">

For tomcat2, put jvmRoute="tomcat2".

For the tomcat2 server, replace port 8005 with 12005.  This will prevent the two servers from conflicting.

Change the AJP13 port

At line 75, in the AJP 13 connector definition, replace:
port="8009"
with:
port="11009"

For tomcat2, replace port 8009 with 12009.


Disable the standalone HTTP port:

We don't want or need our tomcat servers to directly respond to HTTP requests. So we comment out the HttpConnector section between lines and 58 in the server.xml file.

Example:
    <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<!--
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="60000"/>
-->  

Disable the WARP connector

Around 314, comment out the <Connector...WarpConnector...> tag.
Example:
<Service name="Tomcat-Apache">
<!--
    <Connector className="org.apache.catalina.connector.warp.WarpConnector"
     port="8008" minProcessors="5" maxProcessors="75"
     enableLookups="true" appBase="webapps"
     acceptCount="10" debug="0"/>
-->

Do the same thing to tomcat2's server.xml file.



 TESTING Load Sharing

Create $CATALINA_HOME/webapps/ROOT/index.jsp for tomcat1 and tomcat2 with some difference between the two of them (ie. Background colour).  Open a few browser windows and load http://<;;server>/index.jsp û you should notice the difference between them.  Ensure that page reloads give you the same page, and not the index.jsp on the other server.

Back to General e-Business discussion FAQ Index
Back to General e-Business discussion Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close