Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed all content of the page. The jk2 connector is obsolete and should not be used. If anyone is interested, they can see the old version of the page in the history.

Using the JK2 Connector

This is the start of a tutorial on using the JK2 Connector. See also the Self: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)

Wiki Markup
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 RUNNING.txt for 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:

No Format

   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

Starting:

No Format

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:

No Format

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

No Format
 <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:

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

conf/work2er.properties:

No Format

 ["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. Issue the following:

No Format
 chgrp ''group'' work 
 chmod g+s work 

If you have already tried tomcat before doing this, then also issue: chgrp group jk2.socket

conf.d/jk2.conf:

LoadModule jk2_module modules/mod_jk2.so

httpd.conf

No Format

 # 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.

FYI

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

No Format

 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. 


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

Building and Configuring Apache

No Format

./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:

No Format

LoadModule jk2_module modules/mod_jk2.so

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

(note from another author, I couldn't get apache1.3.28 to accept this, I had to use JkSet config:file /usr/local/tomcat/conf/jk/workers2.properties)

No Format

 # 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

No Format

 # 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:

No Format
 <!-- 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.

page is obsolete. All content was removed. See the Connectors documentation on the Tomcat site.

...

CategoryObsoleteHope this helps...