阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Tomcat ( 单机多 Tomcat 并存 )

129次阅读
没有评论

共计 11275 个字符,预计需要花费 29 分钟才能阅读完成。

简介:

Tomcat 扩展(一台服务器运行多个 tomcat)

一、安装 JDK、Tomcat

shell > rpm -ivh jdk-8u25-linux-x64.rpm # 安装 jdk,jdk 版本最好与 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 # 复制三份 tomcat 其中 tomcat1 保持不变
shell > cp -r apache-tomcat-8.0.14 tomcat2
shell > cp -r apache-tomcat-8.0.14 tomcat3

 

二、配置多 Tomcat

 

shell > vim tomcat2/conf/server.xml # 修改 tomcat2
22 <Server port=”8006″ shutdown=”SHUTDOWN”> # 原端口为 8005 修改为 8006
69 <Connector port=”8081″ protocol=”HTTP/1.1″ # 原端口为 8080 修改为 8081
91 <Connector port=”8019″ protocol=”AJP/1.3″ redirectPort=”8443″ /> # 原端口为 8009 修改为 8019

shell > vim tomcat3/conf/server.xml # 修改 tomcat3
22 <Server port=”8007″ shutdown=”SHUTDOWN”> # 原端口为 8005 修改为 8007
69 <Connector port=”8082″ protocol=”HTTP/1.1″ # 原端口为 8080 修改为 8082
91 <Connector port=”8029″ protocol=”AJP/1.3″ redirectPort=”8443″ /> # 原端口为 8009 修改为 8029

 

三、测试

 

shell > echo “welcome to tomcat1” > /usr/local/tomcat1/webapps/ROOT/index.html # 创建首面文件
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 # 启动 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/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar
Tomcat started.

shell > tail /usr/local/tomcat1/logs/catalina.out # 查看日志,这里有 tomcat 的开启、关闭信息
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/tomcat1/webapps/ROOT has finished in 50 ms
31-Oct-2014 16:46:30.624 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [“http-nio-8080”]
31-Oct-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

 

# 可以看到服务启动花费的时间

 

shell > netstat -anpt | grep java # 监听的端口(缺一不可)
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” # 访问一下首页文件
welcome to tomcat1

shell > ps aux | grep java # 看看进程路径也没有问题
root 1304 2.2 8.6 2270808 88064 pts/0 Sl 16:46 0:07 /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/tomcat1/temp org.apache.catalina.startup.Bootstrap start

shell > /usr/local/tomcat1/bin/shutdown.sh # 关闭 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/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar

 

 

shell > /usr/local/tomcat1/bin/startup.sh # 启动 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/tomcat1/bin/bootstrap.jar:/usr/local/tomcat1/bin/tomcat-juli.jar
Tomcat started.

shell > /usr/local/tomcat2/bin/startup.sh # 启动 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 # 启动 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 # 这种情况是 tomcat 还没有完全启动,稍等即可
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 # 日志中也没有出来服务启动成功的标志
31-Oct-2014 16:54:02.840 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
31-Oct-2014 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-Oct-2014 16:54:04.374 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler [“http-nio-8082”]
31-Oct-2014 16:54:04.431 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
31-Oct-2014 16:54:04.442 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler [“ajp-nio-8029”]
31-Oct-2014 16:54:04.457 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
31-Oct-2014 16:54:04.461 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1811 ms
31-Oct-2014 16:54:04.597 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
31-Oct-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 # 现在 tomcat1/2/3 都已经全部启动
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” # 全部可以访问
welcome to tomcat1
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 # 可以看到启动时间有长有短
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 # 进程路径也都没有错
root 1381 1.3 8.4 2270676 86560 pts/0 Sl 16:53 0:06 /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/tomcat1/temp org.apache.catalina.startup.Bootstrap start
root 1411 1.3 8.5 2270808 87144 pts/0 Sl 16:53 0:06 /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 16:54 0:06 /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 # 现在单独关闭任何一个 别的都不受影响
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 16:53 0:06 /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/tomcat1/temp org.apache.catalina.startup.Bootstrap start
root 1441 1.2 8.6 2270836 87804 pts/0 Sl 16:54 0:06 /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+ 17:03 0:00 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

## 可以启动、关闭任意 tomcat,没有顺序之分。唯一注意的一点,就是启动有一个过程,需要稍微等等,不要急。
 只需修改端口即可,无需按照网上所说,要设置变量、更改 catalina.sh 等文件(如有不对的地方,还请各位指正)

更多 Tomcat 相关教程见以下内容

CentOS 6.6 下安装配置 Tomcat 环境  http://www.linuxidc.com/Linux/2015-08/122234.htm

RedHat Linux 5.5 安装 JDK+Tomcat 并部署 Java 项目  http://www.linuxidc.com/Linux/2015-02/113528.htm 

Tomcat 权威指南(第二版)(中英高清 PDF 版 + 带书签)  http://www.linuxidc.com/Linux/2015-02/113062.htm 

Tomcat 安全配置与性能优化 http://www.linuxidc.com/Linux/2015-02/113060.htm 

Linux 下使用 Xshell 查看 Tomcat 实时日志中文乱码解决方案 http://www.linuxidc.com/Linux/2015-01/112395.htm 

CentOS 64-bit 下安装 JDK 和 Tomcat 并设置 Tomcat 开机启动操作步骤 http://www.linuxidc.com/Linux/2015-01/111485.htm 

CentOS 6.5 下安装 Tomcat  http://www.linuxidc.com/Linux/2015-01/111415.htm 

Tomcat 的详细介绍:请点这里
Tomcat 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/129668.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计11275字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中