Introduction to the method of deploying multiple Tomcats on a Linux server at the same time

Recently, I was deploying several projects and required to deploy multiple Tomcats on a new Linux server at the same time. Since I only had the experience of deploying one Tomcat before, I stepped on a lot of pits during the period. Fortunately, the deployment was successful in the end. Without further ado, let’s introduce the method in detail.


server configuration:

  • Linux server (CentOS 7.3)
  • JDK:1.8
  • Tomcat:8.5.6

1. Principle explanation:

  1. When tomcat starts, it will look for the root directory of tomcat, and it will look for it through the two variables CATALINA_BASE and CATALINA_HOME, so the root directory of different tomcat on different servers and the values ​​of the above two variables are different, so We're going to set it up.
  2. The tomcat server needs to be configured with three ports to start. These three ports are configured and enabled by default during installation. Therefore, when you want to run multiple tomcat services, you need to modify these three ports, which cannot be the same to prevent port conflicts.

2. Detailed steps

1. Modify the /etc/profile file

You need to add multiple sets of CATALINA environment variables to the file (add a few sets if you have several tomcats).

####第一个Tomcat####
export CATALINA_BASE=/usr/local/tomcat/apache-tomcat-8.5.6
export CATALINA_HOME=/usr/local/tomcat/apache-tomcat-8.5.6
export TOMCAT_HOME=/usr/local/tomcat/apache-tomcat-8.5.6

####第二个Tomcat####
export CATALINA_BASE=/usr/local/tomcat2/apache-tomcat-8.5.6
export CATALINA_HOME=/usr/local/tomcat2/apache-tomcat-8.5.6
export TOMCAT_HOME=/usr/local/tomcat2/apache-tomcat-8.5.6

If there are multiple tomcats, the method is the same, and you can continue to add them down.

Remember to use source /etc/profile to make it take effect after modification.


2. Modify the catalina.sh file in the root directory bin of other tomcats (except the first tomcat)

The specific operation is to switch to the bin directory of tomcat2, vim catalina.sh, and find the following comment code

# OS specific support.  $var _must_ be set to either true or false.

And add the following code below the above code, the purpose is to find the specific path we configured in the previous step in the /etc/profile configuration file through $ CATALINA_2_BASE and $ CATALINA_2_HOME in the file when tomcat2 starts, and complete the startup process of tomcat2 .

# myself : add
export CATALINA_BASE=$CATALINA_2_BASE
export CATALINA_HOME=$CATALINA_2_HOME

If there are multiple tomcats, the modification method is the same.


3. Modify the port number

In addition to the default configured port number used by the first tomcat (which can be modified if necessary), all subsequent tomcats must modify the port number through the server.xml file in the conf directory under its root directory to prevent port conflicts.

  • http access port (default is port 8080):
<Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
  • Listen to the port closed by tomcat (default is 8005):
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  • Responsible for receiving requests from other http servers (default is 8009):
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

After modifying the port, restart tomcat and open the above ports in the firewall.

Finally, if you can't run multiple tomcats normally at the same time according to the above steps, it may be a problem with the cloud server. Since I use Alibaba Cloud's server, I added security group rules on the cloud server, and other tomcats need to be opened. (for example, the http access ports used by my tomcat2 and tomcat3 are 6060 and 7070), add them to the security group rules, and try it.

write picture description here

Personal guess may be that the security group rules may be higher than the permissions of the firewall on the server, so if you use the above method to deploy multiple tomcats that cannot be successful, you can try this little tip.


The above is the method and detailed steps for deploying multiple tomcats on a Linux server at the same time. I hope it can help you.

Finally, thank you for your patience in reading!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325567982&siteId=291194637