Google
   
       
  HOWTO : Apache2, Mod_JK2, Tomcat 4.1.24 and JDK 1.4 on RedHat Linux 7.3 : TCP/IP Socket    
       
  00. intro    
 

This document will describe how to setup Apache2, Java JDK 1.4, Tomcat 4.1.x and ModJK2 on Redhat Linux 7.3. Tomcat will communicate with Apache2 using a network socket and will need to be launched and completely running before Apache2 is started. Even though RPMs are available, most of the components will be built from source. The exceptions being the JDK 1.4.1 RPM and Tomcat 4.1.24 from a binary tarball.

NOTE: THIS DOCUMENT IS A WORK IN PROGRESS!

 
     
  01. install apache2  
 

Download Apache2 from www.apache.org. The latest version at the time of this document was Apache2.0.46.

<INSTRUCTIONS ON DOWNLOADING AND UNCOMPRESSING THE APACHE2 TARBALL>

To build Apache, perform the following commands...

 
  ./configure --prefix=/usr/local/apache2 --enable-ssl --enable-module=so
make
make install
 
  A version of Apache2 should now be in /usr/local/apache2. You should now test the default config by using  
  /usr/local/apache2/bin/apachectl configtest  
  If the test returns "Syntax OK", you should start up Apache2 to verify it's operation  
  /usr/local/apache2/bin/apachectl start  
  Open http://localhost in a browser, which should display the Apache welcome page.  
     
  02. install Jdk1.4.1  
  <JDK INSTALATION INSTRUCTIONS HERE>  
     
  03. INSTALL TOMCAT  
 

<TOMCAT INSTALLATION INSTRUCTIONS HERE>

NOTE: You will need to start Tomcat before Apache2

Finaly, set CATALINA_HOME and TOMCAT_HOME to point to your Tomcat installation. Add the following lines to /etc/profile.

 
 

export CATALINA_HOME='/usr/local/tomcat'
export TOMCAT_HOME='/usr/local/tomcat'

 
     
  04. INSTALL / BUILD MOD JK2  
 

In this HOWTO, ModJK2 was built from source since a prebuild version was not yet avaliable on the Jakarta site. You can find the source tarball on the Apache website.

http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk2/release/v2.0.2/src/

<explain how to decompress the archive into /user/local/src/jk2/>

The ModJK2 tarball uses Ant to build both the Java connectors for Tomcat and the native modules for Apache2. I was unable to use Ant to build ModJK2 but was successful building just the native components using make.

cd to /usr/local/src/jk2/jakarta-tomcat-connectors-jk2-2.0.2-src/jk/native2 and run configure with the following options...

 
  ./configure \
--with-apxs2=<apache-root-directory>/bin/apxs \
--with-tomcat41=<tomcat-root-directory> \
--with-java-home=<java-root-directory> \
--with-jni \
--with-pcre
 
  An example configure statement might look like this...  
  ./configure --with-apxs2=/usr/local/apache2/bin/apxs \
--with-tomcat41=/usr/local/tomcat \
--with-java-home=/usr/java \
--with-jni \
--with-pcre
 
 

Finally, run make

 
  make  
 

This will build mod_jk2.so and jkjni.so in jakarta-tomcat-connectors-jk2-2.0.2-src/jk/build/jk2/apache2

Copy these files into the modules directory of your Apache2 installation and restart Aapache. On my system, the modules directory was located at...

/usr/local/Apache2/modules

 
     
  05. configure apache2  
 

ModJk2 is a Apache module, which is loaded using the LoadModule command in <apache2 install>/conf/httpd.conf. The syntax for loading the module is as follows..

I have also included Apahce2 configuration examples for SSL and virtual hosting of two domains and three sites.

 
 
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
LoadModule jk2_module modules/mod_jk2.so


# SSL Options required to make Mac IE work with SSL 
SSLSessionCache         dbm:logs/ssl_scache
SSLSessionCacheTimeout  300


# Globaly secure the WEB-INF folder on all document roots 
<Directory "/*/WEB-INF/*">
    AllowOverride None
    Deny from all
</Directory>

NameVirtualHost 12.34.56.78:443
NameVirtualHost 12.34.56.78:80
NameVirtualHost 12.34.56.79:80

#
# Client A's Domains 
#

# domain-a.com
<VirtualHost 12.34.56.78:80>
    DocumentRoot /usr/local/docs/clienta/unsecure
    ServerName domain-a.com
    ServerAlias www.domain-a.com 
    ErrorLog logs/domain-a.com-error_log
    CustomLog logs/domain-a.com-access_log extended 
</VirtualHost>

# secure.domain-a.com - SSL
<VirtualHost 12.34.56.78:443>
    DocumentRoot /usr/local/docs/clienta/secure
    ServerName secure.domain-a.com
    ErrorLog logs/secure.domain-a.com-error_log
    CustomLog logs/secure.domain-a.com-access_log extended
    SSLEngine on
    SSLCertificateFile <your-path-to-secure-certificates>/secure.crt
    SSLCertificateKeyFile <your-path-to-secure-certificates>/secure.key
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP
    CustomLog logs/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>

#
# Client B's Domains
#

# domain-b.com
<VirtualHost 12.34.56.79:80>
    ServerName domain-b.com
    DocumentRoot /usr/local/docs/clientb/domainb
    ServerAlias www.domain-b.com
    ErrorLog logs/domain-b.com-error_log
    CustomLog logs/domain-b.com-access_log extended
</VirtualHost>
 
  While many of the required modJK2 commnads can be placed directly in httpd.config, we will define what content Apache should pass to Tomcat in the workers2.properties file.  
     
  06. Create Workers2.properties  
 

The workers2.properties file configures runtime options of ModJK2 and defines what content should be passed on to Tomcat. The syntax for this file is documented at...

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jk2/jk2/configtc.html

http://jakarta.apache.org/tomcat/tomcat-4.1-doc/jk2/jk2/configtccom.html

To help you get started, here is the workers2.properties file for my system.

This file also contains corresponding entries for the virtual hosts defined in Apache 2

NOTE: you must have unique entires for each host alias you are using: www.domain-a.com and domain-a.com.

 
 
# Shared memory handling. Needs to be set.
[shm]
file=/usr/local/apache2/logs/shm.file
size=1048576


# Example socket channel, explicitly set port and host.
[channel.socket:localhost:8009]
port=8009
host=127.0.0.1


# Example UNIX domain socket
[channel.un:/usr/local/tomcat/work/jk2.socket]
tomcatId=localhost:8009
debug=0


# define the worker
[ajp13:localhost:8009]
#channel=channel.un:/usr/local/tomcat/work/jk2.socket
# To use the TCP/IP socket instead, just comment out the above
# line, and uncomment the one below
channel=channel.socket:localhost:8009


# Announce a "status" worker
[status:status]

[uri:/status/*]
worker=status:status

#
# Client A's Sites
#

# domain-a.com > Tomcat
#
#Uri mapping : domain-a.com
[uri:domain-a.com:80/*.jsp]
worker=ajp13:localhost:8009

#Uri mapping : www.domain-a.com
[uri:www.domain-a:80/*.jsp]
worker=ajp13:localhost:8009

# secure.domain-a.com > Tomcat
#
# Uri mapping : secure.domain-a.com : SSL
[uri:secure.domain-a.com:443/*.jsp]
worker=ajp13:localhost:8009

#
# Client B's Sites
#

# domain-b.com > Tomcat
#
#Uri mapping : domain-b.com
[uri:domain-b.com:80/*.jsp]
worker=ajp13:localhost:8009

# www.domain-b.com > Tomcat
#
#Uri mapping : www.domain-b.com
[uri:www.domain-b.com:80/*.jsp]
worker=ajp13:localhost:8009
 
  Note: you may need to edit the paths in this file if you have installed Tomacat, Apache or the JDK in a different folder than suggested above.  
     
  06. create Jk2.properties  
  The file j2k.properties sets up the Tomcat side of the connection and where we configure Tomcat to run in process with Apache.  
 
## COMMENTS WILL BE _LOST_
## DOCUMENTATION OF THE FORMAT IN JkMain javadoc.
# Set the desired handler list
handler.list=apr,request,channelJni
#
# Override the default port for the socketChannel
channelSocket.port=8019
# Default:
# State where the UNIX domain socket is located
channelUnix.file=/usr/local/tomcat/work/jk2.socket
# Just to check if the the config is working
# shm.file=/usr/local/Apache2/logs/jk2.shm
# In order to enable jni use any channelJni directive
#channelJni.disabled = 0
# And one of the following directives:
# If set to inprocess the mod_jk2 will Register natives itself
# This will enable the starting of the Tomcat from mod_jk2
# apr.jniModeSo=inprocess
# Dynamic library
serverRoot=/usr/local/apache2
apr.NativeSo=/usr/local/apache2/modules/libjkjni.so
 
     
  07. configure tomcat  
 

<GIVE BRIEF OVERVIEW OF TOMCAT CONFIG FILE>

Here is my trimmed down version of server.xml

 
 
<Server port="8005" shutdown="SHUTDOWN" debug="0">

  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
            debug="0"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
            debug="0"/>

 
  <!-- Define the Tomcat Stand-Alone Service -->
  <Service name="Tomcat-Standalone">


    <!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8080" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="100" debug="0" connectionTimeout="20000"
               useURIValidationHack="false" disableUploadTimeout="true" />
    

    <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8009" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="0"
               useURIValidationHack="false"
               protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

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


      <!-- Global logger unless overridden at lower levels -->
      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="catalina_log." suffix=".txt"
              timestamp="true"/>

      <Realm className="org.apache.catalina.realm.MemoryRealm" />
      
      <!-- Client B's Sites -->

      <!-- domain-b.com -->
      <Host name="domain-b.com" debug="1"
                appBase="/usr/local/docs/clientb/domainb"
                unpackWARs="true">
        <Alias>www.domain-b.com</Alias>
        <!--<Valve className="org.apache.catalina.authenticator.SingleSignOn"
                   debug="0"/>

        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="domain-b.com_log." suffix=".txt"
                timestamp="true"/> -->

        <!--  Root Context -->
        <Context path="" docBase="" debug="1"/>

      </Host>

      <!-- Client A's Sites  -->

      <!-- www.domain-a.com  -->
      <Host name="domain-a.com" debug="1"
                appBase="/usr/local/docs/clienta/inscure"
                unpackWARs="true">
        <Alias>www.domain-a.com</Alias>

        <!--<Valve className="org.apache.catalina.authenticator.SingleSignOn"
                   debug="0"/>

        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="domain-a.com_log." suffix=".txt"
                timestamp="true"/> -->

        <!--  Root Context -->
        <Context path="" docBase="" debug="1"/>

      </Host>

      <!-- secure.domain-a.com  -->
      <Host name="secure.domain-a.com" debug="1"
                appBase="/usr/local/docs/clienta/secure"
                unpackWARs="true">

        
        <!--<Valve className="org.apache.catalina.authenticator.SingleSignOn"
                   debug="0"/>
        
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="secure.domain-a.com_log." suffix=".txt"
                timestamp="true"/> -->

        <!--  Root Context -->
        <Context path="" docBase="" debug="1"/>

      </Host>

    </Engine>

  </Service>

 </Server>
 
     
  08. Credits  
 

Here are just a few of the many resources used while setting up Apache2 and Tomcat. Many thanks to those who have taken the time to provide these resources online.

http://www.gregoire.org/howto/Apache2_Jk2_TC4.1.x_JSDK1.4.x.html

http://marc.theaimsgroup.com/?l=tomcat-user&m=105103815630094&w=2

http://www.johnturner.com/howto/rh72-howto.html

 
     
  Last updated on 06.28.2003