You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Using the JK2 Connector

This is the start of a tutorial on using the JK2 Connector. See also the ["TomcatFAQ/ModJK2OnRedHat"] Tomcat FAQ on building mod_jk2 for Red Hat Linux.

See also HowToRedhat8JK2 for configuring Red Hat's Apache with a mod_jk2 binary and Tomcat 4.1

Quick Start for Linux

This is just a quick start for people currently struggling with mod_jk2 and multiple hosts. It is a working configuration. My real content for this page will come in another week or so. But please feel free to collaborate on this page now! (smile)

This is working on Red Hat Linux. I use Unix Domain sockets because they eliminate the need to manage the list of IP ports. [One remaining task is to eliminate the need for the shutdown port. The shutdown command can be sent via AJP13, but the code from StopTomcat (in Tomcat v3.3) needs to be ported to use the connector classes.]

Layout

See the file in the Tomcat distribution called RUNNING.txt for instructions on how to use CATALINA_BASE and CATALINA_HOME.

For each virtual host that will have its own JVM (shared JVM will be discussed later), setup a layout like:

   site/${CATALINA_BASE}
	conf/									   
	logs/									   
	${Host.appBase}/ROOT/					   
	${Host.appBase}/ROOT/web-inf/classes/	   
	${Host.appBase}/ROOT/web-inf/lib/		   
	temp/									   
	work/

This is just a basic description for this example. There are other options for placement of the site content.

Starting and Stopping Tomcat

Starting:

su --login ''user'' --command="export CATALINA_BASE=''path''; export JAVA_HOME=/usr/local/java; export JAVA_OPT=-server; /usr/local/tomcat-4/bin/startup.sh" 

Stopping:

su --login ''user'' --command="export CATALINA_BASE=''path''; export JAVA_HOME=/usr/local/java; export JAVA_OPT=-server; /usr/local/tomcat-4/bin/shutdown.sh"

I use a Sys{{`VI`nit}} script that manages this cleanly for many sites. The user should be in the same group as the apache web server process.

Connector

 <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" } } } 
               port="'''0'''" minProcessors="5" maxProcessors="75" 
               enableLookups="true" redirectPort="8443" 
               acceptCount="10" debug="0" connectionTimeout="0" 
                 useURIValidationHack="false" 
               protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

Note that the port is set to zero. We're using UNIX domain sockets in this example, and we don't want the connector to open a port.

jk2.properties

 handler.list=apr,channelUnix,request 
 apr.NativeSo=/etc/httpd/modules/jkjni.so 
 channelUnix.file=${jkHome}/work/jk2.socket 

conf/worker.properties

 ["logger"] 
 level=DEBUG 

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

 [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 

 [channel.un:''workerName''] 
 info=AF_UNIX socket connecting to "host" 
 file=/''catalina_base''/work/jk2.socket 
 debug=0 

... repeat the above for each worker ...

NOTE: You must make sure that the group owning the work/ directory is the same as the Group directive in httpd.conf. Run the following:

 chgrp group work 
 chmod g+s work

If you have already tried Tomcat before doing this, then also execute the following:

 chgrp group jk2.socket

conf.d/jk2.conf

LoadModule jk2_module modules/mod_jk2.so

httpd.conf

 # This sends all resource requests to tomcat 
 <VirtualHost ...> 
 ServerName ''vhost'' 
 DirectoryIndex index.jsp index.html 
 JkSet uri:''vhost''/*.group ajp13:'' workerName '' 

 # Alternative mapping mechanisms 
 # 1. Place this in workers2.properties 
 # [uri:''vhost''/] 
 # group=ajp13:''workerName'' 
 # 
 # 2. This is the same as above, but in httpd.conf 
 # JkSet uri:''vhost''/*.group ajp13:''workerName'' 
 # 
 # 3. This does the same thing, but with mapping inside httpd 
 #    NOTE: this is currently broken for virtual hosts 
 #<Location "/*"> 
 #   JkUriSet group ajp13:''workerName'' 
 #</Location>
 # 
 # If you have a ServerAlias, methods #1 and #2 
 # require entries for each alias. 

 </VirtualHost>

 # This sends only JSP page requests to tomcat 
 <VirtualHost ...>
 ServerName ''vhost'' 
 DocumentRoot /''catalina_base''/webapps/ROOT/ 
 DirectoryIndex index.jsp index.html 
 JkSet uri:''vhost''/*.jsp.group ajp13:''workerName'' 
 </VirtualHost>

This is only a start. But hopefully it will help people already trying to get this working, and having problems. For the Windows users, and others using TCP/IP ports or other transports, sorry. TCP/IP ports will be in the next revision, or you can glean the workers2.properties and jk2.properties directives from the official JK2 documentation.

Configuring Apache 2.0.47 with Tomcat 4.1.27 and mod_jk 2.0.42

September 3rd 2003 - gturcios

During the last two weeks I was unable to find a good example for configuring Apache 2.0.47, Tomcat 4.1.27 and mod_jk-2.0.42. After piecing together examples and ideas from multiple sources I was able to get these three components to work in a load balanced environment. Each Apache and Tomcat lives on a separate server.

Current Environment

  • 1 WSD (Load Balancer)
  • 3 Apache servers (front-end)
  • 3 Tomcat servers (back-end)

The WSD DS Radware is set up with multiple farm addresses that point to the Apaches' primary and virtual interface IP addresses.

Each Apache server is load balanced by the WSD using a weighted round-robin mechanism.

Each Tomcat server is load balanced between the three Apache servers.

Here is an ASCII diagram (not a good diagram, but better than nothing!):

             WSD 
             /|\
            / | \
  Apache1  Apache2  Apache3 
    /|\      /|\      /|\ 
   / | \    / | \    / | \ 
  tomcat1  tomcat2  tomcat3

Building and Configuring Apache

./configure --prefix=/usr/local/apache2 --enable-so --enable-vhost-alias

Copied mod_jk2.so to /usr/local/apache2/modules.

Add the following lines to httpd.conf:

LoadModule jk2_module modules/mod_jk2.so

<IfModule mod_jk.c>
   JkWorkersFile conf/workers2.properties 
</IfModule>

If you are using Apache 1.3, you might try this instead:

JkSet config:file /usr/local/tomcat/conf/jk/workers2.properties

More:

 # Default DocumentRoot
 # 
 DocumentRoot "/usr/local/apache2/htdocs"
 <location "/*.jsp"> 
   JkUriSet group loadbalancer 
 </location> 
 <location "/servlet/*"> 
   JkUriSet group loadbalancer 
 </location> 
 <location "/test/*"> 
   JkUriSet group loadbalancer 
 </location>

workers2.properties

 # workers2.properties 
 # 
 # Tomcat shared memory component 
 ["shm"] 
 info=Scoreboard required for reconfiguration and status with multiprocess servers 
 file=/usr/local/apache2/logs/jk2.shm 
 size=1048576 
 debug=0 
 disabled=0 

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

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

 # Define Load Balancer worker 
 [lb:loadbalancer] 
 info=Default load balancer 
 debug=0 

 # Define the loadbalancer group communication channel(s) 
 [channel.socket:10.1.1.14:8009] 
 port=8009 
 host=10.1.1.14 
 tomcatId=tomcat1 
 group=loadbalancer 

 [channel.socket:10.1.1.15:8009] 
 port=8009 
 host=10.1.1.15 
 tomcatId=tomcat2 
 group=loadbalancer 

 [channel.socket:10.1.1.16:8009] 
 port=8009 
 host=10.1.1.16 
 tomcatId=tomcat3 
 group=loadbalancer 

server.xml

Added jvmRoute="<unique tomcat id>" to the following line:

 <!-- Define the top level container in our container hierarchy --> 
 <Engine jvmRoute="tomcat1" name="Standalone" defaultHost="localhost" debug="0">

This jvmRoute parameter uniquely identifies the Tomcat server to each Apache server and maintains a sticky session between the two during a user's session.

Hope this helps...

  • No labels