Principle of Tomcat Multi instance Deployment and Configuration

  • 2021-11-02 03:42:47
  • OfStack

1. Close the firewall and transfer the software package required for installing Tomcat to the/opt directory


jdk-8u201-linux-x64.rpm
apache-tomcat-9.0.16.tar.gz
 
systemctl stop firewalld
systemctl disable firewalld
setenforce 0

2. Install JDK


cd /opt
rpm -qpl jdk-8u201-linux-x64.rpm
rpm -ivh jdk-8u201-linux-x64.rpm
java -version

3. Install Tomcat


cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz
mkdir /usr/local/tomcat
mv apache-tomcat-9.0.16 /usr/local/tomcat/tomcat1
cp -a /usr/local/tomcat/tomcat1 /usr/local/tomcat/tomcat2

4. Configure tomcat environment variables


vim /etc/profile.d/tomcat.sh
#tomcat1
export CATALINA_HOME1=/usr/local/tomcat/tomcat1
export CATALINA_BASE1=/usr/local/tomcat/tomcat1
export TOMCAT_HOME1=/usr/local/tomcat/tomcat1
 
#tomcat2
export CATALINA_HOME2=/usr/local/tomcat/tomcat2
export CATALINA_BASE2=/usr/local/tomcat/tomcat2
export TOMCAT_HOME2=/usr/local/tomcat/tomcat2
 
 
source /etc/profile.d/tomcat.sh

5. Modify the server. xml file in tomcat2, and require that each tomcat instance configuration cannot have duplicate port numbers


vim /usr/local/tomcat/tomcat2/conf/server.xml
<Server port="8006" shutdown="SHUTDOWN">      #22 Row, modify Server prot The default is 8005 ->  Modify to 8006
<Connector port="8081" protocol="HTTP/1.1"       #69 Row, modify Connector port , HTTP/1.1   Default to 8080 ->  Modify to 8081
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />  #116 Row, modify Connector port AJP/1.3 The default is 8009 ->  Modify to 8010

6. Modify startup. sh and shutdown. sh files in each tomcat instance and add tomcat environment variable


vim /usr/local/tomcat/tomcat1/bin/startup.sh
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
## Add the following 
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1
 
 
vim /usr/local/tomcat/tomcat1/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1
 
vim /usr/local/tomcat/tomcat2/bin/startup.sh
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2
 
vim /usr/local/tomcat/tomcat2/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2

7. Start the/bin/startup. sh in each tomcat


/usr/local/tomcat/tomcat1/bin/startup.sh
/usr/local/tomcat/tomcat2/bin/startup.sh
 
netstat -natp | grep java

Related articles: