Create multiple Tomcat instances for the same installation 

Joined:
03/21/2010
Posts:
49

December 29, 2011 13:31:44    Last update: December 29, 2011 14:29:13
Tomcat allows you to create multiple server instances for the same installation. The installation directory is identified as CATALINA_HOME, the instance directory is identified as CATALINA_BASE. Here are the steps:
  1. Create a base directory for the new instance, for example: /home/nogeek/tomcat1.
  2. Create the subdirectories:
    mkdir -p /home/nogeek/tomcat/{bin,conf,logs,temp,webapps,work}
    

  3. Copy web.xml from the installation directory:
    cp $CATALINA_HOME/conf/web.xml /home/nogeek/tomcat1/conf/
    

  4. Copy logging.properties from the installation directory:
    cp $CATALINA_HOME/conf/logging.properties /home/nogeek/tomcat1/conf/
    

  5. Create server.xml under tomcat1/conf:
    <?xml version='1.0' encoding='utf-8'?>
    <Server port="8085" shutdown="SHUTDOWN">
      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off"/>
      <Listener className="org.apache.catalina.core.JasperListener"/>
      <!-- Prevent memory leaks due to use of particular java/javax APIs-->
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
      <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
    
      <Service name="Catalina">
        <Connector port="8088" protocol="HTTP/1.1" 
    	       URIEncoding="UTF-8"
                   connectionTimeout="20000" 
                   redirectPort="8443" />
    
        <Engine name="Catalina" defaultHost="localhost">
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
    	<Valve className="org.apache.catalina.valves.AccessLogValve" 
    	       directory="logs"
                   prefix="localhost_access_log." 
    	       suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
          </Host>
        </Engine>
      </Service>
    </Server>
    

  6. Create script setenv.sh under tomcat1/bin:
    # Edit this file to set custom options
    # Tomcat accepts two parameters JAVA_OPTS and CATALINA_OPTS
    # JAVA_OPTS are used during START/STOP/RUN
    # CATALINA_OPTS are used during START/RUN
    JAVA_HOME="/usr/java"
    AGENT_PATHS=""
    JAVA_AGENTS=""
    JAVA_LIBRARY_PATH=""
    CLASSPATH=""
    JVM_OPTS="-Xmx512M -Xss192K -XX:MaxPermSize=256m -Djava.awt.headless=true"
    JAVA_OPTS="$JVM_OPTS $AGENT_PATHS $JAVA_AGENTS $JAVA_LIBRARY_PATH"
    

  7. Copy startup.sh and shutdown.sh from the installation directory. Add the following two lines to the beginning of each:
    CATALINA_BASE=/home/nogeek/tomcat1
    export CATALINA_BASE
    

  8. Create a soft link for catalina.sh in tomcat1/bin:
    $ ln -s ~/apache-tomcat-7.0.22/bin/catalina.sh catalina.sh
    

Share |
| Comment  | Tags