Tomcat (coexistence of multiple single-host Tomcat servers)

Source: Internet
Author: User

Tomcat (coexistence of multiple single-host Tomcat servers)

Introduction:

Tomcat extension (one server runs multiple tomcat servers)

1. Install JDK and Tomcat

Shell> rpm-ivh jdk-8u25-linux-x64.rpm # Install jdk, jdk version is best consistent with tomcat

Shell> tar zxf apache-tomcat-8.0.14.tar.gz-C/usr/local/
Shell> cd ..
Shell> cp-r apache-tomcat-8.0.14 tomcat1 # copy three copies of tomcat, where tomcat1 remains unchanged.
Shell> cp-r apache-tomcat-8.0.14 tomcat2
Shell> cp-r apache-tomcat-8.0.14 tomcat3

 

2. Configure multiple Tomcat servers

 

Shell> vim tomcat2/conf/server. xml # modify tomcat2
22 <Server port = "8006" shutdown = "SHUTDOWN"> # change the original port to 8005
69 <Connector port = "8081" protocol = "HTTP/1.1" # change the original port to 8080
91 <Connector port = "8019" protocol = "AJP/1.3" redirectPort = "8443"/> # change the original port to 8009

Shell> vim tomcat3/conf/server. xml # modify tomcat3
22 <Server port = "8007" shutdown = "SHUTDOWN"> # change the original port to 8005
69 <Connector port = "8082" protocol = "HTTP/1.1" # change the original port to 8080
91 <Connector port = "8029" protocol = "AJP/1.3" redirectPort = "8443"/> # change the original port to 8009

 

Iii. Test

 

Shell> echo "welcome to cmdat1">/usr/local/cmdat1/webapps/ROOT/index.html # create the first file
Shell> echo "welcome to tomcat2">/usr/local/tomcat2/webapps/ROOT/index.html
Shell> echo "welcome to tomcat3">/usr/local/tomcat3/webapps/ROOT/index.html

Shell>/usr/local/tomcat1/bin/startup. sh # Start tomcat1
Using CATALINA_BASE:/usr/local/tomcat1
Using CATALINA_HOME:/usr/local/tomcat1
Using CATALINA_TMPDIR:/usr/local/tomcat1/temp
Using JRE_HOME:/usr
Using CLASSPATH:/usr/local/export AT1/bin/bootstrap. jar:/usr/local/export AT1/bin/tomcat-juli.jar
Tomcat started.

Shell> tail/usr/local/tomcat1/logs/catalina. out # view logs. Here, tomcat's enabling and disabling information is available.
31-Oct-2014 16:46:29. 296 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deployment of web application directory/usr/local/tomcat1/webapps/manager has finished in 104 MS
31-Oct-2014 16:46:29. 301 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deploying web application directory/usr/local/tomcat1/webapps/examples
31-Oct-2014 16:46:30. 488 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deployment of web application directory/usr/local/tomcat1/webapps/examples has finished in 1,187 MS
31-Oct-2014 16:46:30. 492 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deploying web application directory/usr/local/tomcat1/webapps/docs
31-Oct-2014 16:46:30. 557 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deployment of web application directory/usr/local/tomcat1/webapps/docs has finished in 65 MS
31-Oct-2014 16:46:30. 564 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deploying web application directory/usr/local/tomcat1/webapps/ROOT
31-Oct-2014 16:46:30. 614 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deployment of web application directory/usr/local/incluat1/webapps/ROOT has finished in 50 MS
31---2014 16:46:30. 624 INFO [main] org. apache. coyote. AbstractProtocol. start Starting ProtocolHandler ["http-nio-8080"]
31---2014 16:46:30. 643 INFO [main] org. apache. coyote. AbstractProtocol. start Starting ProtocolHandler ["ajp-nio-8009"]
31-Oct-2014 16:46:30. 649 INFO [main] org. apache. catalina. startup. Catalina. start Server startup in 2772 MS

 

# You can see the service startup time

 

Shell> netstat-anpt | grep java # listening port (unavailable)
Tcp 0 0: 8080: * LISTEN 1304/java
Tcp 0 0: ffff: 127.0.0.1: 8005: * LISTEN 1304/java
Tcp 0 0: 8009: * LISTEN 1304/java

Shell> curl "http: // 192.168.1.80: 8080" # access the homepage File
Welcome to strongat1

Shell> ps aux | grep java # Check whether the process path is correct.
Root 1304 2.2 8.6 2270808 88064 pts/0 Sl/usr/bin/java-Djava. util. logging. config. file =/usr/local/tomcat1/conf/logging. properties-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/usr/local/tomcat1/endorsed-classpath/usr/local/tomcat1/bin/bootstrap. jar:/usr/local/tomcat1/bin/tomcat-juli.jar-Dcatalina. base =/usr/local/tomcat1-Dcatalina. home =/usr/local/tomcat1-Djava. io. tmpdir =/usr/local/cmdat1/temp org. apache. catalina. startup. bootstrap start

Shell>/usr/local/tomcat1/bin/shutdown. sh # disable tomcat1
Using CATALINA_BASE:/usr/local/tomcat1
Using CATALINA_HOME:/usr/local/tomcat1
Using CATALINA_TMPDIR:/usr/local/tomcat1/temp
Using JRE_HOME:/usr
Using CLASSPATH:/usr/local/export AT1/bin/bootstrap. jar:/usr/local/export AT1/bin/tomcat-juli.jar

 

 

Shell>/usr/local/tomcat1/bin/startup. sh # Start tomcat1
Using CATALINA_BASE:/usr/local/tomcat1
Using CATALINA_HOME:/usr/local/tomcat1
Using CATALINA_TMPDIR:/usr/local/tomcat1/temp
Using JRE_HOME:/usr
Using CLASSPATH:/usr/local/export AT1/bin/bootstrap. jar:/usr/local/export AT1/bin/tomcat-juli.jar
Tomcat started.

Shell>/usr/local/tomcat2/bin/startup. sh # Start tomcat2
Using CATALINA_BASE:/usr/local/tomcat2
Using CATALINA_HOME:/usr/local/tomcat2
Using CATALINA_TMPDIR:/usr/local/tomcat2/temp
Using JRE_HOME:/usr
Using CLASSPATH:/usr/local/tomcat2/bin/bootstrap. jar:/usr/local/tomcat2/bin/tomcat-juli.jar
Tomcat started.

Shell>/usr/local/tomcat3/bin/startup. sh # Start tomcat3
Using CATALINA_BASE:/usr/local/tomcat3
Using CATALINA_HOME:/usr/local/tomcat3
Using CATALINA_TMPDIR:/usr/local/tomcat3/temp
Using JRE_HOME:/usr
Using CLASSPATH:/usr/local/tomcat3/bin/bootstrap. jar:/usr/local/tomcat3/bin/tomcat-juli.jar
Tomcat started.

 

 

Shell> netstat-anpt | grep java # in this case, tomcat has not been fully started yet. Just wait.
Tcp 0 0: 8080: * LISTEN 1381/java
Tcp 0 0: 8081: * LISTEN 1411/java
Tcp 0 0: 8082: * LISTEN 1441/java
Tcp 0 0: 8019: * LISTEN 1411/java
Tcp 0 0: 8029: * LISTEN 1441/java
Tcp 0 0: 8009: * LISTEN 1381/java

Shell> tail/usr/local/tomcat3/logs/catalina. out # The log does not indicate that the service is successfully started.
31---2014 16:54:02. 840 INFO [main] org. apache. catalina. startup. VersionLoggerListener. log JVM Vendor: Oracle Corporation
16:54:03. 619 INFO [main] org. apache. catalina. core. aprLifecycleListener. init The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java. library. path:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
31---2014 16:54:04. 374 INFO [main] org. apache. coyote. AbstractProtocol. init Initializing ProtocolHandler ["http-nio-8082"]
31---2014 16:54:04. 431 INFO [main] org.apache.tomcat.util.net. NioSelectorPool. getSharedSelector Using a shared selector for servlet write/read
31---2014 16:54:04. 442 INFO [main] org. apache. coyote. AbstractProtocol. init Initializing ProtocolHandler ["ajp-nio-8029"]
31---2014 16:54:04. 457 INFO [main] org.apache.tomcat.util.net. NioSelectorPool. getSharedSelector Using a shared selector for servlet write/read
31---2014 16:54:04. 461 INFO [main] org. apache. catalina. startup. Catalina. load Initialization processed in 1811 MS
31---2014 16:54:04. 597 INFO [main] org. apache. catalina. core. StandardService. startInternal Starting service Catalina
31---2014 16:54:04. 601 INFO [main] org. apache. catalina. core. StandardEngine. startInternal Starting Servlet Engine: Apache Tomcat/8.0.14
31-Oct-2014 16:54:04. 628 INFO [localhost-startStop-1] org. apache. catalina. startup. HostConfig. deployDirectory Deploying web application directory/usr/local/tomcat3/webapps/host-manager

 

 

Shell> netstat-anpt | grep java # Now worker AT1/2/3 has all started
Tcp 0 0: 8080: * LISTEN 1381/java
Tcp 0 0: 8081: * LISTEN 1411/java
Tcp 0 0: 8082: * LISTEN 1441/java
Tcp 0 0: 8019: * LISTEN 1411/java
Tcp 0 0: 8029: * LISTEN 1441/java
Tcp 0 0: ffff: 127.0.0.1: 8005: * LISTEN 1381/java
Tcp 0 0: ffff: 127.0.0.1: 8006: * LISTEN 1411/java
Tcp 0 0: ffff: 127.0.0.1: 8007: * LISTEN 1441/java
Tcp 0 0: 8009: * LISTEN 1381/java

Shell> curl "http: // 192.168.1.80: 8080" # All accesses
Welcome to strongat1
Shell> curl "http: // 192.168.1.80: 8081"
Welcome to tomcat2
Shell> curl "http: // 192.168.1.80: 8082"
Welcome to tomcat3

 

Shell> tail-1/usr/local/tomcat1/logs/catalina. out # You can see that the startup time is long or short.
31-Oct-2014 16:55:11. 536 INFO [main] org. apache. catalina. startup. Catalina. start Server startup in 74454 MS

Shell> tail-1/usr/local/tomcat2/logs/catalina. out
31-Oct-2014 16:58:30. 971 INFO [main] org. apache. catalina. startup. Catalina. start Server startup in 269855 MS

Shell> tail-1/usr/local/tomcat3/logs/catalina. out
31-Oct-2014 16:56:10. 965 INFO [main] org. apache. catalina. startup. Catalina. start Server startup in 126503 MS

Shell> ps aux | grep java # no error in the process path
Root 1381 1.3 8.4 2270676 86560 pts/0 Sl/usr/bin/java-Djava. util. logging. config. file =/usr/local/tomcat1/conf/logging. properties-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/usr/local/tomcat1/endorsed-classpath/usr/local/tomcat1/bin/bootstrap. jar:/usr/local/tomcat1/bin/tomcat-juli.jar-Dcatalina. base =/usr/local/tomcat1-Dcatalina. home =/usr/local/tomcat1-Djava. io. tmpdir =/usr/local/cmdat1/temp org. apache. catalina. startup. bootstrap start
Root 1411 1.3 8.5 2270808 87144 pts/0 Sl/usr/bin/java-Djava. util. logging. config. file =/usr/local/tomcat2/conf/logging. properties-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/usr/local/tomcat2/endorsed-classpath/usr/local/tomcat2/bin/bootstrap. jar:/usr/local/tomcat2/bin/tomcat-juli.jar-Dcatalina. base =/usr/local/tomcat2-Dcatalina. home =/usr/local/tomcat2-Djava. io. tmpdir =/usr/local/tomcat2/temp org. apache. catalina. startup. bootstrap start
Root 1441 1.4 8.6 2270836 87784 pts/0 Sl/usr/bin/java-Djava. util. logging. config. file =/usr/local/tomcat3/conf/logging. properties-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/usr/local/tomcat3/endorsed-classpath/usr/local/tomcat3/bin/bootstrap. jar:/usr/local/tomcat3/bin/tomcat-juli.jar-Dcatalina. base =/usr/local/tomcat3-Dcatalina. home =/usr/local/tomcat3-Djava. io. tmpdir =/usr/local/tomcat3/temp org. apache. catalina. startup. bootstrap start

 

 

Shell>/usr/local/tomcat2/bin/shutdown. sh # Close either of them independently.
Using CATALINA_BASE:/usr/local/tomcat2
Using CATALINA_HOME:/usr/local/tomcat2
Using CATALINA_TMPDIR:/usr/local/tomcat2/temp
Using JRE_HOME:/usr
Using CLASSPATH:/usr/local/tomcat2/bin/bootstrap. jar:/usr/local/tomcat2/bin/tomcat-juli.jar

Shell> ps aux | grep java
Root 1381 1.2 8.4 2270676 86572 pts/0 Sl/usr/bin/java-Djava. util. logging. config. file =/usr/local/tomcat1/conf/logging. properties-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/usr/local/tomcat1/endorsed-classpath/usr/local/tomcat1/bin/bootstrap. jar:/usr/local/tomcat1/bin/tomcat-juli.jar-Dcatalina. base =/usr/local/tomcat1-Dcatalina. home =/usr/local/tomcat1-Djava. io. tmpdir =/usr/local/cmdat1/temp org. apache. catalina. startup. bootstrap start
Root 1441 1.2 8.6 2270836 87804 pts/0 Sl/usr/bin/java-Djava. util. logging. config. file =/usr/local/tomcat3/conf/logging. properties-Djava. util. logging. manager = org. apache. juli. classLoaderLogManager-Djava. endorsed. dirs =/usr/local/tomcat3/endorsed-classpath/usr/local/tomcat3/bin/bootstrap. jar:/usr/local/tomcat3/bin/tomcat-juli.jar-Dcatalina. base =/usr/local/tomcat3-Dcatalina. home =/usr/local/tomcat3-Djava. io. tmpdir =/usr/local/tomcat3/temp org. apache. catalina. startup. bootstrap start
Root 1546 0.0 0.0 103248 864 pts/0 S + grep java

Shell> netstat-anpt | grep java
Tcp 0 0: 8080: * LISTEN 1381/java
Tcp 0 0: 8082: * LISTEN 1441/java
Tcp 0 0: 8029: * LISTEN 1441/java
Tcp 0 0: ffff: 127.0.0.1: 8005: * LISTEN 1381/java
Tcp 0 0: ffff: 127.0.0.1: 8007: * LISTEN 1441/java
Tcp 0 0: 8009: * LISTEN 1381/java

# Any tomcat can be started or shut down without any order. The only thing to note is that there is a process to start, which requires a little bit of wait. Don't rush.
You only need to modify the port. You do not need to set variables or change files such as catalina. sh according to the instructions on the Internet. (if there are any errors, please correct them)

For more Tomcat tutorials, see the following:

Install and configure the Tomcat environment in CentOS 6.6

Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects

Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)

Tomcat Security Configuration and Performance Optimization

How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux

Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure

Install Tomcat in CentOS 6.5

Tomcat details: click here
Tomcat: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.