20120621 multiple tomcats single install - plembo/onemoretech GitHub Wiki

title: Multiple tomcats, single install link: https://onemoretech.wordpress.com/2012/06/21/multiple-tomcats-single-install/ author: lembobro description: post_id: 2904 created: 2012/06/21 20:53:08 created_gmt: 2012/06/22 00:53:08 comment_status: closed post_name: multiple-tomcats-single-install status: publish post_type: post

Multiple tomcats, single install

This is for those who need to run multiple instances of Tomcat out of a single install. There are a few different ways to do this. Here's the one I find easiest and least confusing: 1. Download Tomcat from the Apache site. http://tomcat.apache.org/download-60.cgi 2. Unzip to install directory.

/opt/apache/tomcat6

This will be your $CATALINA_HOME. 3. Create a tomcat6 user and group (try to use the same uid and gid values across systems: you'll thank me later). Use the "tomcat6" name to avoid colliding with any system install of Tomcat (like Red Hat's tomcat6-* packages) that may use the "tomcat" name. 4. Chown the install directory for the new user and group. Also give group write permissions on the entire directory. 5. Create a subdirectories for your instances, for example: /opt/apache/tomcat6/inst1 /opt/apache/tomcat6/inst2 These will each be a $CATALINA_BASE. 6. Copy the following directories from $CATALINA_HOME into each $CATALINA_BASE: conf logs temp work webapps You can remove these from under $CATALINA_HOME (except for logs and temp) to reduce confusion and clutter (if you ever need a clean copy, you can always extract from the original .zip file). 7. Edit each $CATALINA_BASE/conf/server.xml to change the default ports to something unique for each instance (the HTTP listen port from 8080 to 8081, for example). 8. Create a new startup and shutdown script under $CATALINA_HOME/bin for each instance by copying the existing startup.sh and shutdown.sh to new files named for the instance. For example: "inst1-startup.sh", "inst1-shutdown.sh". Include all the usual environment variables here, for example:

JAVA_HOME=/usr/java/default
CATALINA_OPTS="$JAVA_OPTS -Xmx1024m -XX:MaxPermSize=256m"
CATALINA_HOME=/opt/apache/tomcat6
CATALINA_BASE=$CATALINA_HOME/testam
export JAVA_HOME CATALINA_OPTS CATALINA_HOME CATALINA_BASE

(Note: you should leave the "CATALINA_OPTS" line out of the shutdown scripts to avoid using additional memory) You could also put this is a separate .env file and source it within the script, but do you really want to make things that complex? Some people prefer to create a separate "bin" directory under each $CATALINA_BASE. My reason for not doing so is the same I have for renaming the original startup and shutdown .sh files to .sh.orig and making them un-executable: reducing confusion on the part of the uninitiated to a minimum. If you've ever been awakened at 3 AM to explain your wily scripting ways to a panicky sysadmin, you'll understand what I'm talking about. 9. Create a custom init script (like the one here) that includes your CATALINA_HOME and CATALINA_BASE definitions and points at your custom startup and shutdown scripts (rather than the now renamed originals).

Copyright 2004-2019 Phil Lembo