Deploy two Tomcat on one linux host

Posted by disaster77 on Sat, 06 Nov 2021 16:57:04 +0100

@

catalogue

1. Basic principles

(https://blog.csdn.net/shmily_lsl/article/details/80718508)

tomcat startup can be started through two scripts:. / startup.sh or catalina.sh run. In fact, the startup of startup.sh is also called catalina.sh, and then started, so we need to pay attention to the catalina.sh file

  1. First, when Tomcat starts, it will find the installation directory of tomcat, that is, its root directory, and then use CATALINA_BASE and Catalina_ The home variables are used to search, so the root directories of multiple different Tomcat on a server and the values of the above two variables are different. Therefore, we need to set the above two variables.
  2. The next step is to set the three ports of each server so that the three corresponding ports of each tomcat are different, so as to ensure the success of starting multiple Tomcats at the same time.

2. Start configuration

1. Prepare multiple Tomcat

1. First, copy two copies of tomcat and change its name to make it easy to remember

mv apache-tomcat-8.5.55 apache-tomcat-8080

Make a copy,

cp -r apache-tomcat-8080 apache-tomcat-18080

After the operation, view the following results:

[root@node2 opt]# ls
apache-tomcat-18080  apache-tomcat-8080

2. Set CATALINA_BASE and CATALINA_HOME variable

  • vim /etc/profile

  • Delete the previous environment variable configuration about tomcat

  • Configure the root directory of Catalina and Tomcat

#tomcat 8080
export CATALINA_HOME=/opt/apache-tomcat-8080
export CATALINA_BASE=/opt/apache-tomcat-8080
export TOMCAT_HOME=/opt/apache-tomcat-8080

#tomcat 18080
export CATALINA_HOME18080=/opt/apache-tomcat-18080
export CATALINA_BASE18080=/opt/apache-tomcat-18080
export TOMCAT_HOME18080=/opt/apache-tomcat-18080
  • Exit save and
source /etc/profile

3. Set three ports for each server

Because we only deploy two, we only need to reset one, and the other remains the default. Here we modify the of apache-tomcat-18080.

  1. Enter / opt/apache-tomcat-8080/conf/server.xml
vim /opt/apache-tomcat-8080/conf/server.xml 
  1. Use the command to find: Server port, Connector port
 :/Server port:
 :/Connector port
  1. Modify Server port
<Server port="8005" shutdown="SHUTDOWN">

by

<Server port="18005" shutdown="SHUTDOWN">
  1. Modify Connector port
<Connector port="8080" protocol="HTTP/1.1"

by

<Connector port="18080" protocol="HTTP/1.1"
  1. Modify Connector protocol
<Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="8443" />

by

<Connector protocol="AJP/1.3"
             address="::1"
             port="18009"
             redirectPort="8443" />

4. Modify Catalina.sh script

  • Modify the script of tomcat18080
vim  /opt/apache-tomcat-18080/bin/catalina.sh
  • Insert content on line 119 (cygwin=false) of this file
export CATALINA_BASE=$CATALINA_BASE18080
export CATALINA_HOME=$CATALINA_HOME18080
export TOMCAT_HOME=$TOMCAT_HOME18080
  • Exit save

5. Operation inspection

  1. First, check whether the previous tomcat is running. If it is running, kill it
ps -ef | grep tomcat
  1. Start tomcat on port 8080
sh /opt/tomcat8080/bin/startup.sh

3. Start tomcat on port 18080

sh /opt/tomcat18080/bin/startup.sh

6. Test

Visit 8080

okk!
Visit 18080

okk!

Topics: Nginx