Create multiple Tomcat instances for the same installation
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:
- Create a base directory for the new instance, for example:
/home/nogeek/tomcat1. - Create the subdirectories:
mkdir -p /home/nogeek/tomcat/{bin,conf,logs,temp,webapps,work} - Copy
web.xmlfrom the installation directory:cp $CATALINA_HOME/conf/web.xml /home/nogeek/tomcat1/conf/
- Copy
logging.propertiesfrom the installation directory:cp $CATALINA_HOME/conf/logging.properties /home/nogeek/tomcat1/conf/
- Create
server.xmlundertomcat1/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 "%r" %s %b" /> </Host> </Engine> </Service> </Server>
- Create script
setenv.shundertomcat1/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"
- Copy
startup.shandshutdown.shfrom the installation directory. Add the following two lines to the beginning of each:CATALINA_BASE=/home/nogeek/tomcat1 export CATALINA_BASE
- Create a soft link for
catalina.shintomcat1/bin:$ ln -s ~/apache-tomcat-7.0.22/bin/catalina.sh catalina.sh