Tomcat HOWTO
Introduction:
This document contains information related to the setup and configuration of Tomcat , the jk connect, and an apache's virtual host. Actually, I don't use that set-up anymore: My tomcat instances are now on servers that don't need apache. Also, should you have apache 2.2, don't use the jk connector, but
General configuration: - SuSe 9.3 - Apache/2.0.53 as front-end (the best solution in term of performance and SSL support) and creation of a virtual host redirecting everything to Tomcat - tomcat-5.5.12: last stable release (at the time of my set-up), supporting Servlet Specifications 2.4 and JSP Specifications 2.0. - Jakarta Tomcat Connectors jk-1.2.14 (apache module mod_jk).
Software Installation :
Tomcat 5.5 is designed to run on J2SE 5.0 and later. In addition, Tomcat 5.5 uses the Eclipse JDT Java compiler for compiling JSP pages. This means you no longer need to have the complete Java Development Kit (JDK) to run Tomcat, but a Java Runtime Environment (JRE) is sufficient. The Eclipse JDT Java compiler is bundled with the binary Tomcat distributions.
1 - Download and Install the J2SE Runtime Environment (JRE) from http://java.sun.com/j2se. (J2SE(TM) Runtime Environment 5.0 Update 5 at time of this installation). We installed J2SE Runtime Environment in the form of RPM packages, not the self-extracting binary file (as a root: ./jre-1_5_0_<version>-linux-i586-rpm.bin)
NB: Self-extracting Binary File - This file can be used to install the J2SE Runtime Environment in a location chosen by the user. This one can be installed by anyone (not only root users), and it can easily be installed in any location. As long as you are not root user, it cannot displace the system version of the Java platform suppled by Linux.
Verify that the software has been installed: myhost:/home/myuser # rpm -qa | grep jre jre-1.5.0_05-fcs
Remember also to set an environment variable named JAVA_HOME to the pathname of the directory into which you installed the JRE, in this case: /usr/java/jre1.5.0_05. To have it set globally, create the file profile.local in /etc and write: export JAVA_HOME=/usr/java/jre1.5.0_05
2 - Download and Install the Tomcat Binary Distribution
- I personnaly put in /opt/jakarta and make s symbolic to tomcat ("ln -s apache-tomcat-5.5.12/ tomcat") so that I don't have to change all the path when I upgrade tomcat - copy the following start-up file to /etc/init.d and modify it with the right path:
#!/bin/sh # # tomcat This shell script takes care of starting and stopping # tomcat. # description: tomcat is a servlet/JSP engine, which can be used # standalone or in conjunction with Apache ### BEGIN INIT INFO # Provides: Tomcat # Required-Start: $local_fs $network $remote_fs apache2 # Required-Stop: $local_fs $network $remote_fs apache2 # Default-Start: 3 5 # Default-Stop: 0 1 2 6 # Short-Description: Tomcat # Description: Tomcat ### END INIT INFO RETVAL=0 # See how we were called. case "$1" in start) # Start daemons. echo -n "Starting tomcat: " cd ~tomcat su - tomcat -c '/opt/jakarta/tomcat/bin/catalina.sh start' RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/tomcat echo ;; stop) # Stop daemons. echo -n "Shutting down tomcat: " cd ~tomcat su - tomcat -c '/opt/jakarta/tomcat/bin/catalina.sh stop' RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/tomcat echo ;; restart) $0 stop $0 start RETVAL=$? ;; *) echo "Usage: tomcat {start|stop|restart}" exit 1 esac exit $RETVAL
- insserv –d tomcat to automatically start the service at boot time - as you probably noticed from my init.d script, I start the tomcat service using a non-root user. That's because I configure Tomcat to listen on port 8080 and use apache as a front-end. For this reason you need to create the group and user tomcat and change the permission on the folder /opt/jakarta (chown -R tomcat.tomcat /opt/jakarta)) - Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it. cp -R server/webapps/admin/ /opt/jakarta/tomcat/server/webapps/ cp conf/Catalina/localhost/admin.xml /opt/jakarta/tomcat/conf/Catalina/localhost/ chown –R tomcat.tomcat on /opt/jakarta/tomcat
3 Connector configuration
This part is required only if you use apache as a front-end (translation: you can already start tomcat and go to http://yourhost:808080) To connect Tomcat to Apache, we need to use:
- mod_jk, the Tomcat redirector module. The ajp13 protocol should be used, as it’s the only one known by Tomcat 4 and 5
- Setup working entities, i.e Workers, between the apache and Tomcat engines using the mandatory workers.properties file
A Tomcat worker is a Tomcat instance that is waiting to execute servlets or any other content on behalf of some web server. For example, we can have a web server such as Apache forwarding servlet requests to a Tomcat process (the worker) running behind it. In our case, we will probably configure two Tomcat workers: this way we will have the different contexts (test and production) served by different Tomcat workers. Concrete steps are: 1 Copy the example config file /usr/share/doc/packages/mod_jk-ap20/jk.conf to /etc/apache2/conf.d and modify the path 2 Copy the example config file /usr/share/doc/packages/mod_jk-ap20/workers.properties to /opt/jakarta/tomcat 3 Add the module "jk" to the list of apache2 modules by editing /etc/sysconfig/apache2. 4 Create the apache virtual host, something that can be as easy as:
<VirtualHost myhost:80> ServerAdmin webmaster@myhost ServerName myhost DocumentRoot "/opt/jakarta/tomcat/webapps" ErrorLog /var/log/apache2/myhost-error_log CustomLog /var/log/apache2/myhost-access_log combined <Location "/*"> JkUriSet worker ajp13:localhost:8009 </Location> </VirtualHost>