Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1


Ratings: (0)|Views: 28|Likes:
Published by api-3730516
Configuração do servidor WEB Apache e múltiplos java web containers Tomcat.
Configuração do servidor WEB Apache e múltiplos java web containers Tomcat.

More info:

Published by: api-3730516 on Oct 15, 2008
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Connecting Apache's Web Server to
Multiple Instances of Tomcat
By Daniel McCarthy
Created 2005-09-13 01:00
Learn how to use mod_jk to forward requests to specific hosts when more than
one Tomcat instance is running.

Recently, I was asked to reorganize some of our Web applications to improve
their stability. The major push was to get each of our applications running in its
own instance of Tomcat. These applications all are in various stages of
development, and if a single instance allocates all of the memory available, the
entire Tomcat server must be restarted. This, in turn, brings down all of the
other applications.

An obstacle to running multiple instances is each instance would have to run on
a unique port. Enter Apache's Web server. With the use of mod_jk, we were
able to forward requests to specific hosts and contexts to the respective
running instance of Tomcat.

Pulling all of this together was not the hardest thing I've done; however, it did
prove challenging due to a lack of documentation. By no means, though, is this
statement a stab at any of the development teams. In fact, the developers
themselves helped me on numerous occasions when I found myself in over my
head. When the documentation had me confused or I could not find exactly
what I was looking for, I would head over to #tomcat or #apache on
irc.freenode.org and pose my question there. Usually, I received a response
within minutes.

The following software was used for the purposes of this article. See the
resources section at the end of this article for download locations:

\ue000J2sdk1.4.2_09 \ue000Tomcat 5.0.28 \ue000Apache 2.0.54 \ue000mod_jk 1.2.14

I am certain some of you are wondering why I used the Java software
development kit (SDK) rather than the Java runtime environment (JRE). The
P\u00e1gina 1 de 10
Connecting Apache's Web Server to Multiple Instances of Tomcat

answer is simple: Tomcat requires tools.jar to compile JSP pages, and tools.jar
is provided in the SDK. If you do not wish to use the SDK, you need to place
tools.jar in $CATALINA_HOME\common\lib.


For the purposes of this article, I assume that you already have Apache, Java
and Tomcat installed. With all of the software listed above installed, except
mod_jk, let's set up our environment.

In order for Tomcat to start, you need to set two environment variables,
JAVA_HOME and CATALINA_HOME. JAVA_HOME should point to the J2sdk
installation directory, and CATALINA_HOME should point to the installation
directory for Tomcat. To make life easier, I have placed the following lines
in /etc/bashrc:

export JAVA_HOME=/usr/java/j2sdk1.4.2_09
export CATALINA_HOME=/opt/tomcat

Notice that I have set CATALINA_HOME to /opt/tomcat. Although this is the
case, /opt/tomcat actually is a symlink to /opt/jakarta-tomcat-5.0.28. Although
you can tell which version of Tomcat you have installed by running

$CATALINA_HOME/bin/catalina.sh version, I prefer to be able to note the version
immediately by looking at the installation directory.

Before we dive into compiling mod_jk, I would like to dispel some confusion I
came across while working on this project. Specifically, the confusion centers
around the myth that bigger is better. In the world of Tomcat connectors, there
exists mod_jk and mod_jk2. In my mind mod_jk2 was the logical choice, as it
had a higher version number. After a bit of probing and inquiring, however, I
discovered that mod_jk2 is deprecated--it is no longer being developed.
Unfortunately for me, I had invested several hours in getting mod_jk2 to work
when I discovered this fact. Hopefully, you will have saved yourself some time
by reading this article.

Compiling, Installing and Configuring mod_jk

Open a terminal and change directories to the location where you have saved the mod_jk source. See the Resources section at the end of this article for the download link. In the terminal window, extract the source archive and install with the following four lines:

tar -xzvf jakarta-tomcat-connectors-
cd jakarta-tomcat-connectors-
./configure --with-axps=/usr/sbin/axps
make && make install

P\u00e1gina 2 de 10
Connecting Apache's Web Server to Multiple Instances of Tomcat

The --with-axps=/usr/sbin/apxs configuration option allows us to build Apache
modules without requiring the Apache source. If all goes well, you should see a
message near the end informing you of the location of the libraries. On my
distribution, it is /usr/lib/httpd/modules.

With mod_jk installed, we must now configure Apache to load the module by
editing httpd.conf. httpd.conf is located in /etc/httpd/conf on my system.
Configuring Apache to load mod_jk is a simple two-line step:

#Load the mod_jk connector LoadModule jk_module
A mistake I initially made was naming the module mod_jk, as inLoadModule
mod_jk /usr/lib/httpd/modules/mod_jk.so. The above command is certain to make

Apache complain and refuse to start. With that said, it is a good idea to start or
restart Apache now to verify that it can load the newly compiled module. If
Apache starts without a problem, it is safe to continue.

Setting Up Multiple Tomcat Instances

Multiple Tomcat instances are possible to create with the use of the
CATALINA_BASE environment variable. Each instance uses a common binary
distribution but uses its own conf, webapps, temp, logs and work directories.
Each instance also has its own JVM and, thereby, its own memory pool. If you
have defined the maximum memory to be 512MB via JAVA_OPTS, each
instance will attempt to allocate a maximum of 512MB.

Let's proceed now to set up these directories. As I mentioned before, Tomcat is
installed in /opt/tomcat. To keep things somewhat organized, I created the
following folders in /opt: /opt/tomcat_instance1, /opt/tomcat_instance2
and /opt/tomcat_instance3. It probably is more appropriate, however, to name
these folders based on their purposes or applications. Remember that each of
the three folders will contain conf, webapps, temp and work directories.

Configuring the First Instance

Tomcat uses a server.xml configuration file to determine the ports, connector
engines and various other "server" configuration options. We are going to copy
the installed server.xml from $CATALINA_HOME/conf/server.xml
to /opt/tomcat_instance1/conf/server.xml. While we are at it, we might as well
copy $CATALINA_HOME/con/server.xml
to /opt/tomcat_instance2/conf/server.xml
and /opt/tomcat_instance3conf/server.xml as well.

Tomcat also uses a global web.xml file. By global, I mean it is used for each
instance. The web.xml file provides the default configuration for each Web
application running under the given instance. If an option is not defined in the

P\u00e1gina 3 de 10
Connecting Apache's Web Server to Multiple Instances of Tomcat

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->