next up previous contents
Next: 20 KRUD Updates Up: Redhat FAQ Previous: 18 Time Services   Contents

Subsections

19 InstallingTomcat

By:
Stephen Carville
Rev:
08/26/03
  1. From local ftp or from the Jakarta Project Web Site download the latest stable versions of Ant, and Tomcat. Because we are interested in the developing Server Side Includes (SSI) rather than hacking the technology, the binaries are perfectly good.
  2. Create a directory for the Jakarta software. Here we use /var/jakarta.
  3. Change to the newly created directory.
  4. As necessary, extract the jakarta-ant and jakarta-tomcat archives to this directory.
  5. Create some useful symlinks 
    # ln -s jakarta-ant-<version> ant  
    # ln -s jakarta-tomcat-<version tomcat
  6. If necesary source the changes in the Java setup script
  7. Start the tomcat server
    # /var/jakarta/tomcat/bin/startup.sh
  8. If no errors are reported open a browser and connect to port 8080.
  9. Shutdown the tomcat server
    # /var/jakarta/tomcat/bin/startup/shutdown.sh
  10. Make any necessary changes to the configuration
  11. Create a startup script so tomcat is started as a service at boot. (See: 19.3)


19.1 Using mod_jk

19.1.1 Build and Install

  1. Make certain axps is installed. This is part of the apache-devel package
  2. Extract the archive
    $ tar -xvzf jakarta-tomcat-connectors-jk-<version>-src.tar.gz
  3. Change to the the native directory
    $ cd jakarta-tomcat-connectors-jk-<version>-src/jk/native
  4. Run the buildconf script
    $ ./buildconf.sh
  5. Run the configure script
    $ ./configure -with-apxs=/usr/sbin/apxs
  6. Make the module
    $ make
  7. Copy the module to the Apache modules directory
    $ sudo cp apache-1.3/mod_jk.so /etc/httpd/modules/.

19.1.1.1 Building by hand

This is not necessary on Linux but I usually have to do it this way on Solaris

  1. Change to the native directory
    $ cd jakarta-tomcat-connectors-jk-<version>-src/jk/native
  2. Build using apxs
    $ apxs -o mod_jk.so -Icommon -I/usr/java/jdk/include usr/java/jdk/include/solaris -c apache-1.3/*.c common/*.c
  3. Copy the module to the Apache modules directory
    $ sudo cp mod_jk.so /etc/httpd/modules/.

19.1.2 Configure Apache

  1. Change to the apache configuration directory
    $ cd /etc/httpd/conf
  2. Create a workers.conf file containing at a minimum:
    worker.list=worker1 
    worker.worker1.type=ajp13 
    worker.worker1. 
    worker.worker1.port=8009 
    worker.worker1.lbfactor=50 
    worker.worker1.cachesize=10 
    worker.worker1.cache_timeout=600 
    worker.worker1.socket_keepalive=1 
    worker.worker1.socket_timeout=300
  3. Add to httpd.conf:
    LoadModule jk_module modules/mod_jk.so 
     
    # Declare the module for <IfModule directives> 
    AddModule mod_jk.c 
     
    # Where to find workers.properties 
    JkWorkersFile /etc/httpd/conf/workers.conf 
     
    # Where to put mod_jk logs  
    JkLogFile /var/log/httpd/mod_jk.log 
     
    # Set the jk log level [debug/error/info]  
    JkLogLevel info
  4. Restart Apache

19.1.3 Apache Virtual Host

Alias /cert/ /var/jakarta/tomcat/webapps/cert/  
 
<VirtualHost *>  
  ServerName     www.dpsi-corp.com  
  DocumentRoot   /var/jakarta/dpsi-corp/ROOT  
  DirectoryIndex HomePage.jsp index.html  
  JkMount        /*.jsp worker1  
</VirtualHost>

19.1.4 Configure Tomcat

  1. Create an AJP 1.3 connector
    <!- Define an AJP 1.3 Connector on port 8009 -> 
    <Connector className="org.apache.ajp.tomcat4.Ajp13Connector" 
      port="8009"  
      minProcessors="5"  
      maxProcessors="75"  
      acceptCount="10"  
      debug="0" 
    />
  2. Restart tomcat

19.1.5 Tomcat Virtual Host

<Host name = "www.dpsi-corp.com" debug = "0"  
  appBase="/var/jakarta/dpsi-corp">  
  <Context path="" docBase="ROOT" /> 
</Host>

19.2 Multiple Tomcat Servers on one Machine.

This is not a good solution but is sometimes necessary. If possible use mod_jk and Apache (See: 19.1)

  1. Create a sub interface with a different IP address (See: 8.1.1)
  2. Make a copy of the tomcat directory
    $ cp -r jakarta-tomcat-<version> jakarta-tomcat-<version>-2
  3. Symlink the new directory to a new name
    $ ln -s jakarta-tomcat-<version>-2 tomcat-2
  4. Edit <tomcat-directory>/conf/server.xml to add an address and change the shutdown port and the AJP port. Some examples:

    <Server port="8005" shutdown="SHUTDOWN" debug="0"> 
     
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" 
      address="192.168.124.221" port="80"  
      minProcessors="5" maxProcessors="75"  
      enableLookups="true"  
      redirectPort="8443"  
      acceptCount="10" debug="0"  
      connectionTimeout="20000"
      useURIValidationHack="false" /> 
     
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"  
      port="8009"  
      minProcessors="5" maxProcessors="75"  
      enableLookups="true"  
      redirectPort="8443"  
      acceptCount="10" debug="0"  
      connectionTimeout="20000"  
      useURIValidationHack="false"  protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>
  5. Create a startup file with the differences between the two installs. This will usually only be TOMCAT_HOME and CATALINA_HOME. For example:

    #! /bin/bash  
    # set up for tomcat-2  
    # source the regular tomcat stuff  
    . /etc/java.sh 
     
    # changes for tomcat-2  
    TOMCAT_HOME=$JAKARTA_HOME/tomcat-2 
    CATALINA_HOME=$JAKARTA_HOME/tomcat-2 
     
    export CATALINA_HOME TOMCAT_HOME


19.3 Example Tomcat Startup Script

#! /bin/bash 
# # Startup script for the Tomcat Server  
# be certain the start and stop priority for chkconfig  
# starts tomcat before httpd and the runlevel list matches httpd.  
# Otherwise, apache may choke. Shutdown is less important  
#  
# chkconfig: 345 80 20  
# description: starts and stop the tomcat java server 
# 
SU=/bin/su 
USER=tomcat 
 
# source tomcat stuff 
. /etc/java.sh 
 
start() {
     echo -n "Starting tomcat: " 
     $SU - $USER -c $TOMCAT_HOME/bin/startup.sh 
     RTNVAL=$? 
     return $RTNVAL 
} 
 
stop() { 
     echo -n "Shutting down tomcat: " 
     $SU - $USER -c $TOMCAT_HOME/bin/shutdown.sh 
     RTNVAL=$? 
     return $RTNVAL 
} 
 
# See how we were called.  
case "$1" in  
     start)  
          start  
          ;;
     stop)  
          stop  
          ;;  
     restart)  
          stop  
          start  
          ;;  
     *)  
          echo "Usage: $0 {start|stop|restart}"  
          exit 1  
esac 
 
exit $RETVAL


next up previous contents
Next: 20 KRUD Updates Up: Redhat FAQ Previous: 18 Time Services   Contents
2005-03-20