tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Abhijit Aklujkar" <a_abhi...@hotmail.com>
Subject Apache2+ mod_jk2+ MultipleTomcats 4.1.X in Load Balancing and Context Switching
Date Mon, 06 Oct 2003 04:48:54 GMT
Applies to Unix Like OS, FreeBSD and Configuration Part applies to all
platforms including Windows (All). The article contains the step by step 
guidelines to achieve the above configuration.

Complete Configuration of Apache2+ mod_jk2+ Multiple Tomcat 4.1.X  in
Load Balancing and Context  Switching Mode:

To begin with its always a good Idea to start from scratch by
downloading the src's and staqrt from compiling unless you are very
sure for using of the avialable binaries.

Download Apache2 from http://httpd.apache.org/download.cgi
JDK 1.4.X from http://java.sun.com/j2se/
mod_jk2 from 
http://www.apache.org/dist/jakarta/tomcat-connectors/jk2/source/
Tomcat4.1.X from http://jakarta.apache.org/tomcat/

APACHE INSTALLATION OVERVIEW (I chose httpd-2.0.47.tar.gz)

  For complete installation documentation, see
[ht]docs/manual/install.html or
  http://httpd.apache.org/docs-2.0/install.html

Unzipped the tar as /usr/local/apachesrc

     $ ./configure --prefix=/usr/local/apache
     $ make
     $ make install
     $ /usr/local/bin/apachectl start


Java SDK
I chose the J2SE v1.4.2 SDK Linux self-extracting binary file.
Change to the directory where you downloaded the SDK and make the
self-extracting binary executable:

chmod +x j2sdk-1_4_2-linux-i586.bin

Run the self-extracting binary:

./j2sdk-1_4_2-linux-i586.bin

There should now be a directory called j2sdk1.4.2 in the download
directory. Move the SDK directory to where you want it to be
installed. I chose to install it in /usr/java. Create /usr/java if it
doesn't exist. Here is the command I used from inside the download
directory:

mv j2sdk1.4.2 /usr/java

Set the JAVA_HOME environment variable, by modifying /etc/profile so
it includes the following:

JAVA_HOME="usr/java/j2sdk1.4.2"
export JAVA_HOME

There will be other environment variables being set in /etc/profile,
so you will probably be adding JAVA_HOME to an existing export
command. /etc/profile is run at startup and when a user logs into a
system (or can also put in ~/.bash_profile)

Tomcat :
Download the latest release build from
http://www.apache.org/dist/jakarta/tomcat-4/binaries/. Since Tomcat
runs directly on top of a standard JDK, I cannot think of any reason
to building it from source.
The Tomcat binary is available in two different flavors:
non-LE
Full binary distribution
Includes all optional libraries and an XML parser (Xerces)
Can be run on JDK 1.2+
LE
Lightweight binary distribution
Designed to be run on JDK 1.4
Does not include an XML parser because one is included in JDK 1.4
Can be run on JDK 1.2 by adding an XML parser
All the components of this distribution are open source software
Does not include any of the following optional binaries: JavaMail,
Java Activation Framework, Xerces, JNDI, or the JDBC Standard
Extension
There are a number of different download formats.
I chose the zipped tar file (jakarta-tomcat-4.1.27.tar.gz).

Tomcat Standalone
Unzip Tomcat by issuing the following command from your download
directory:
tar xvzf tomcat-4.1.27.tar.gz

This will create a directory called tomcat-4.1.27.tar.gz. Move this
directory to wherever you would like to install Tomcat. I chose
/usr/local. Here is the command I issued from inside the download
directory:
mv jakarta-tomcat-4.1.27 /usr/local/

The directory where Tomcat is installed is referred to as
CATALINA_HOME in the Tomcat documentation.
In this case CATALINA_HOME=/usr/local/jakarta-tomcat-4.1.27

It is not necessary to set the CATALINA_HOME environment variable.
Tomcat is smart enough to figure out CATALINA_HOME on its own.
You should now be able to start and stop Tomcat from the
CATALINA_HOME/bin directory by typing ./startup.sh and ./shutdown.sh
respectively. Test that Tomcat is working by starting it and typing
http://localhost:8080 into your browser. You should see the Tomcat
welcome page with links to documentation and sample code. Verify
Tomcat is working by clicking on some of the examples links and
executing jsp (s) listed there.

Selecting A Connector
At this point, Apache and Tomcat should be working separately in
standalone mode. You can run Tomcat in standalone mode as an
alternative to Apache. In fact, in some cases, it is said that Tomcat
standalone is faster than serving static content from Apache and
dynamic content from Tomcat. However, there are compelling reasons to
use Apache as the front end. If you run Tomcat standalone:
You will have to run Tomcat as root on port 80. This is a security
concern.
You will not be able to use a connector such as mod_jk to load balance
amongst several Tomcat instances.
You will not be able to take advantage of Apache features such as cgi
and PHP.
You will not be able to take advantage of Apache modules such as
mod_rewrite.
You will not be able to isolate virtual hosts in their own Tomcat
instances.
I think the increased functionality obtained by using Apache on the
front end far outweighs the effort required to install and configure a
connector. With that said, I selected the tried and true mod_jk
connector. It has been around a long while and is very stable. mod_jk2
is the wave of the future, but I'm holding off on that for now. In
early 2002 I invested a considerable amount of time on the "wave of
the future" connector at that time, mod_webapp, which is now no longer
being developed. For that reason, I am being cautious about migrating
to mod_jk2.

Building the mod_jk Connector
The mod_jk connector is the communication link between Apache and
Tomcat. It listens on port 8009 for requests from Apache.
In my experience, it's safest to think of connectors as being version
dependent. If you upgrade Tomcat and you have a connector issue, try
compiling the connector using the version-specific connector source.
I choose jakarta-tomcat-connectors-jk2-2.0.2-src.zip
Copy the unzip to /usr/local/mod_jksrc

Run the buildconf script to to create the /jk/native/configure file.
./usr/local/mod_jksrc/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/native2/buildconf.sh

Run the configure script with the path to the apxs file on your system
and the options below:
cd /usr/local/mod_jksrc/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/native2
./configure --with-apxs=/usr/local/apache/bin/apxs

Build mod_jk with the following command:

make

If all went well, the mod_jk.so file was successfully created.
Manually copy it to Apache's shared object files directory: Its a good
idea to rename the files (?? if they are present??) at the destination
and prevent them from getting overwritten.

cp 
/mod_jksrc/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/build/jk2/apache2/mod_jk2.so
/etc/httpd/modules

cp 
/usr/local/mod_jksrc/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/conf/workers2.properties
  /usr/local/apache/conf

cp  
/usr/local/mod_jksrc/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/conf/jk2.properties
   /usr/local/jakarta-tomcat-4.1.27/conf


Ask apache to load the modeul by adding  Under  ### Section 1: Global
Environment in /usr/local/apache/conf/httpd.conf add following for
loading the mod_jk2 module

LoadModule jk2_module modules/mod_jk2.so

Configuring mod_jk2 in various modes- Load Balancing, Context
Switching:

Make /etc/hosts file entries for the host Matrix and Surya.
Check them by pinging the hosts after the entries for the IP address
resolution. I haven't checkup directly puting IP address but I read
somewhere that mod_jk2 has issues working with dots(.)
In the scenario below there are three contexts

/examples/*  pointing to Localhost
/PCargo/*  pointing to two hosts "Matrix" and "Surya" (load balanced 1:10)

>                                            +------+                        
>                       +--->| TC0  |- /examples/*
>        ----        +         +------+----+  |    +------+ (localhost)
>       /    \--     +   +---->|      |    |--+
>     --        \    +   |     +httpd0+mjk2+  |    +------+  (matrix)
>    / Internet /--->+---+                    +--->| tc01 |- /PCargo/*      
>\__      --              |    +------+ \__/         |    +------+  (surya)
>                                             +--->| tc02 |- /PCargo/*       
>                                              +------+

Here 's the sample workers2.properties applicalble for the above
scenario
************************************************************************
[logger]
level=DEBUG

[config:]
file=${serverRoot}/conf/workers2.properties
debug=0
debugEnv=0

[uriMap:]
info=Maps the requests. Options: debug
debug=0

# Alternate file logger
#[logger.file:0]
#level=DEBUG
#file=${serverRoot}/logs/jk2.log

[shm:]
info=Scoreboard. Required for reconfiguration and status with
multiprocess servers
file=${serverRoot}/logs/jk2.shm
size=1000000
debug=0
disabled=0

[workerEnv:]
info=Global server options
timing=1
debug=0
# Default Native Logger (apache2 or win32 )
# can be overriden to a file logger, useful
# when tracing win32 related issues
#logger=logger.file:0

[lb:lb]
info=Default load balancer.
#******************************************

debug=0

[lb:lb_1]
info=A second load balancer.
#******************************************

debug=0

#[lb:lb_2]
#info=A second load balancer.
#debug=0

[channel.socket:localhost:8009]
#******************************************whole stanza
info=Ajp13 forwarding over socket
debug=0
tomcatId=localhost:8009

[channel.socket:surya:8009]
#******************************************whole stanza
info=A second tomcat instance.
debug=0
tomcatId=surya:8009
lb_factor=1 #******************************************
group=lb
group=lb_1 #******************************************
disabled=0

[channel.socket:matrix:8009]
#******************************************whole stanza
info=A second tomcat instance.
debug=0
tomcatId=surya:8009
lb_factor=10 #******************************************
group=lb
group=lb_1 #******************************************
disabled=0


[channel.un:/opt/33/work/jk2.socket]
info=A second channel connecting to localhost:8019 via unix socket
tomcatId=localhost:8019
lb_factor=1
debug=0

[channel.jni:jni]
info=The jni channel, used if tomcat is started inprocess

[status:]
info=Status worker, displays runtime informations

[vm:]
info=Parameters used to load a JVM in the server process
#JVM=C:\jdk\jre\bin\hotspot\jvm.dll
classpath=${TOMCAT_HOME}/bin/tomcat-jni.jar
classpath=${TOMCAT_HOME}/server/lib/commons-logging.jar
OPT=-Dtomcat.home=${TOMCAT_HOME}
OPT=-Dcatalina.home=${TOMCAT_HOME}
OPT=-Xmx128M
#OPT=-Djava.compiler=NONE
disabled=1

[worker.jni:onStartup]
info=Command to be executed by the VM on startup. This one will start
tomcat.
class=org/apache/jk/apr/TomcatStarter
ARG=start
# For Tomcat 5 use the 'stard' for startup argument
# ARG=stard
disabled=1
stdout=${serverRoot}/logs/stdout.log
stderr=${serverRoot}/logs/stderr.log

[worker.jni:onShutdown]
info=Command to be executed by the VM on shutdown. This one will stop
tomcat.
class=org/apache/jk/apr/TomcatStarter
ARG=stop
disabled=1

[uri:/jkstatus/*]
info=Display status information and checks the config file for
changes.
group=status:

[uri:127.0.0.1:8003]
info=Example virtual host. Make sure myVirtualHost is in /etc/hosts to
test it
alias=myVirtualHost:8003

[uri:127.0.0.1:8003/ex]
info=Example webapp in the virtual host. It'll go to lb_1 ( i.e.
localhost:8019 )
context=/ex
group=lb_1

[uri:/examples]  #******************************************whole
stanza
info=Example webapp in the default context.
context=/examples
debug=0

[uri:/PCargo/*]  #******************************************whole
stanza
info=A second webapp, this time going to the second tomcat only.
group=lb_1  #******************************************
debug=0

[uri:/PCargo/*]  #******************************************whole
stanza
info=A second webapp, this time going to the third tomcat only.
group=lb_1  #******************************************
debug=0


[uri:/examples/servlet/*]
info=Prefix mapping

[uri:/examples/*.jsp]
info=Extension mapping

[uri:/examples/*]
info=Map the whole webapp

[uri:/examples/servlet/HelloW]
info=Example with debug enabled.
debug=10
************************************************************************
Check for the lines marked  with
#****************************************** (remove this if you are
using the same file in your configuration)

In the above configuration check for the worker group lb_1 designated
for the conetxt /PCargo/* and the load balancing weight (per host)
associated with it.i.e The lb_factor for matrix is 10 and Surya is 1
i.e. the workers for matrix work more and so as the matrix server will
be more busy than Surya.

_________________________________________________________________
Contact brides & grooms FREE! http://www.shaadi.com/ptnr.php?ptnr=hmltag 
Only on www.shaadi.com. Register now!


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message