Parent Tomcat – apache-tomcat-9.0.12
Child Tomcat – <instance_name>-tomcat
tar -xvzf apache-tomcat-9.0.12.tar.gz under /u02/tomcat, it will create apache-tomcat-9.0.12 directory
cp -R apache-tomcat-9.0.12.tar.gz dev-tomcat (Create child instance directory from Parent)
/u02/tomcat/dev-tomcat
Keep only bin,conf,logs,temp,webapps, and work, also remove all the files from /u02/tomcat/dev-tomcat/bin and ADD setenv.sh
vi /u02/tomcat/dev-tomcat/bin/setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS-Xms256m"export CATALINA_OPTS="$CATALINA_OPTS-Xmx1024m"export CATALINA_OPTS="$CATALINA_OPTS-XX:MaxPermSize=512m" |
At this point /u02/tomcat should have
drwxr-xr-x 8 oracle dba 4096 Sep 25 11:38 dev-tomcatdrwxr-xr-x 5 oracle dba 4096 Sep 25 11:41 apache-tomcat-9.0.12 |
Parent Tomcat directory (/u02/tomcat/apache-tomcat-9.0.12)
Remove conf,logs,temp,webapps, and work folder
Create a dicrectory “controller” under /u02/tomcat/apache-tomcat-9.0.12
cat /u02/tomcat/apache-tomcat-9.0.12/controller/startup.sh
#!/usr/bin/env shapp_instance=$1;BASE_TOMCAT=/u02/tomcat/export CATALINA_HOME=$BASE_TOMCAT/apache-tomcat-9.0.12export CATALINA_BASE=$BASE_TOMCAT/$app_instance$CATALINA_HOME/bin/startup.sh |
cat /u02/tomcat/apache-tomcat-9.0.12/controller/shutdown.sh
#!/usr/bin/env shapp_instance=$1;BASE_TOMCAT=/u02/tomcat/export CATALINA_HOME=$BASE_TOMCAT/apache-tomcat-9.0.12export CATALINA_BASE=$BASE_TOMCAT/$app_instance$CATALINA_HOME/bin/shutdown.sh |
chmod u+x on above two scripts
chown under /u02 so that you won’t need to be root user to run these.
Tomcat Port Configuration
Child Tomcat Directory, /u02/tomcat/dev-tomcat/conf/server.xml (Multiple tomcat instances, change this value under different child tomcat instance)
<Server port="8007" shutdown="SHUTDOWN"><Connector port="8090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /><Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> |
Ensure above ports aren’t conflicting with each other on for all the instances.
start and shutdown each tomcat instance using scripts under controller directory from Parent Tomcat Instance ONLY
/u02/tomcat/apache-tomcat-9.0.12/controller/startup.sh <child tomcat directory>/u02/tomcat/apache-tomcat-9.0.12/controller/shutdown.sh <child tomcat directory>example: /u02/tomcat/apache-tomcat-9.0.12/controller/startup.sh dev-tomcat/u02/tomcat/apache-tomcat-9.0.12/controller/shutdown.sh dev-tomcat |
At this point you can see a generic Apache Tomcat page running
<hostname>:8090
Starting tomcat services at Boot time
cd to /etc/init.d as Root
Since multiple tomcat server instances are running on Tomcat Server host, it is best to separate them into each startup script (or combine them all into single tomcatstartup)
Create DEVtomcatstartup under /etc/init.d
#!/bin/bash## tomcat## Source function library. /etc/init.d/functions#RETVAL=$?export CATALINA_HOME=/u02/tomcat/apache-tomcat-9.0.12ERROR=0case $1 instart)sh /u02/tomcat/apache-tomcat-9.0.12/controller/startup.sh dev-tomcat;;stop)sh /u02/tomcat/apache-tomcat-9.0.12/controller/shutdown.sh dev-tomcat;;restart)sh /u02/tomcat/apache-tomcat-9.0.12/controller/shutdown.sh dev-tomcatsh /u02/tomcat/apache-tomcat-9.0.12/controller/startup.sh dev-tomcat;;*)echo $"Usage: $0 (start|stop|restart}";exit 1;;esac#exit $RETVALexit 0 |
Multiple startup scripts are located under /etc/init.d/
-rwxrwxrwx 1 root root 552 Oct 15 11:14 DEVtomcatstartup-rwxrwxrwx 1 root root 556 Oct 15 11:14 TESTtomcatstartup-rwxrwxrwx 1 root root 560 Oct 15 11:15 TRAINtomcatstartup-rwxrwxrwx 1 root root 552 Oct 15 11:15 ADTtomcatstartup |
Create the following symbolic link under /etc/rc5.d
lrwxrwxrwx 1 root root 28 Oct 15 11:16 S12DEVtomcatstartup -> /etc/init.d/DEVtomcatstartuplrwxrwxrwx 1 root root 29 Oct 15 11:17 S12TESTtomcatstartup -> /etc/init.d/TESTtomcatstartuplrwxrwxrwx 1 root root 30 Oct 15 11:17 S12TRAINtomcatstartup -> /etc/init.d/TRAINtomcatstartuplrwxrwxrwx 1 root root 28 Oct 15 11:17 S12ADTtomcatstartup -> /etc/init.d/ADTtomcatstartup |
Create the following symbolic link under /etc/rc6.d
lrwxrwxrwx 1 root root 28 Oct 15 11:20 K13DEVtomcatstartup -> /etc/init.d/DEVtomcatstartuplrwxrwxrwx 1 root root 29 Oct 15 11:21 K13TESTtomcatstartup -> /etc/init.d/TESTtomcatstartuplrwxrwxrwx 1 root root 30 Oct 15 11:21 K13TRAINtomcatstartup -> /etc/init.d/TRAINtomcatstartuplrwxrwxrwx 1 root root 28 Oct 15 11:21 K13ADTtomcatstartup -> /etc/init.d/ADTtomcatstartup |
tomcat instances will start at Boot time.
I could also use service command to start,stop,restart tomcat servers
service DEVtomcatstartup [start,stop,restart]