Tomcat ( 单机多 Tomcat 并存 )

简介:

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 # 关闭 tomcat1Using CATALINA_BASE: /usr/local/tomcat1Using CATALINA_HOME: /usr/local/tomcat1Using CATALINA_TMPDIR: /usr/local/tomcat1/tempUsing JRE_HOME: /usrUsing 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 等文件(如有不对的地方,还请各位指正)

时间: 2024-10-16 18:06:48

Tomcat ( 单机多 Tomcat 并存 )的相关文章

Tomcat单机多实例部署-多项目部署

博文说明[前言]: 本文将通过个人口吻介绍Tomcat单机多实例部署,在目前时间点[2017年8月13号]下,所掌握的技术水平有限,可能会存在不少知识理解不够深入或全面,望大家指出问题共同交流,在后续工作及学习中如发现本文内容与实际情况有所偏差,将会完善该博文内容. 本文参考文献及引用文章链接: 1.http://wiki.jikexueyuan.com/project/tomcat/ [Tomcat 8 权威指南-极客学院出品] 2.<Tomcat 权威指南> 2.http://www.cn

[转载]Tomcat单机多实例配置

Tomcat单机多实例配置 当一个进程的线程超过500个的话,那么这个进程的运行效率会变得很低.因为一个进程产生过多的线程,CPU资源会浪费在线程间切换过程当中.但当服务器配置很高的情况下,如:32G内存,16核的CPU.这样一台高配的机器上只装一个Tomcat实例,会有点浪费.其实我们可以根据服务器的硬件配置,配置多个Tomcat实例,充分利用硬件的资源.你第一时间可能会想到,直接下载多份Tomcat安装包,直接解压,改下端口跑起来不就可以了? 这样也是可以的,但不好维护.假设你在一台机器上安

Docker 快速验证 tomcat 单机多实例方案

概述 主要讲的是解决问题的思路.当然也附带了尽可能详细的步骤,感兴趣的童鞋可以一步一步跟着来实践一把.因为运维职业的缘故,基本上是把事故当故事来写了,希望能够喜欢. 缘起 至少10年了,没在一线玩过 Tomcat 了,这次客户现场就来了一场遭遇战.虽然客户说了他来搭建,但是项目进度不等人,还是自己动手吧.当然了,新服务器是要走流程申请的,只能在现有服务器想办法.犹记得当年解决 Tomcat 部署这些都是小菜,没想到在苛刻的商业环境中,处处是坑,步步有雷.不过,咱干过开发也干过运维,这点儿动手的事

tomcat单机多实例

catalina.home指向公用信息的位置,就是bin和lib的父目录. catalina.base指向每个Tomcat目录私有信息的位置,就是conf.logs.temp.webapps和work的父目录. 仅运行一个Tomcat实例时,这两个属性指向的位置是相同的. tomcat单机多实例的部署. 步骤如下: 1.下载一个免安装版本的tomcat7. 2.在tomcat目录创建一个tomcat-ins文件夹,该文件夹作为多实例的根目录. 3.分别针对每个实例创建自己的tomcat目录文件夹

tomcat单机多应用部署,Nginx负载均衡

一.Windows 1. 安装两个tomcat服务器以上 2. 配置环境变量 CATALINA_BASE:D:\servers\Tomcat8 CATALINA_HOME:D:\servers\Tomcat8 TOMCAT_HOME:D:\servers\Tomcat8 CATALINA_2_BASE:D:\servers\Tomcat8 - 2 CATALINA_2_HOME:D:\servers\Tomcat8 - 2 TOMCAT_2_HOME:D:\servers\Tomcat8 - 2

Linux Tomcat安装,Linux配置Tomcat,Linux Tomcat修改内存,Linux tomcat修改端口

Linux Tomcat安装,Linux配置Tomcat,Linux Tomcat修改内存,Linux tomcat修改端口 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ?Copyright 蕃薯耀 2017年3月1日 http://www.cnblogs.com/fanshuyao/ JDK安

Tomcat 设计模式总结(Tomcat源代码阅读系列之八)

本篇我们将来分析一下Tomcat中所涉及到设计模式,本文我们将主要来分析外观模式,观察者模式,责任链模式,模板方法模式,命令模式. 在开始本文之前,笔者先说明一下对于设计模式的一点看法.笔者曾经经常看到网上有人讨论设计模式,也偶尔会遇到有人非要严格按照GOF设计模式的类图以及其中的角色去套用别人的设计,只要类图不一样,或者角色多了或者少了就会觉得怎么和官方定义的模式不一样,其实这都是对设计模式的误解.设计模式其实不仅仅存在软件行业,各行各业其实都有模式,它是所在行业对一些通用问题解决方案的总结和

tomcat cluster和tomcat+memcached实现Session会话保持

Tomcat Cluster: tomcat基于内存复制的集群,tomcat集群各节点通过建立tcp链接来实现session的复制,tomcat启动时,一个cluster对象(默认配置下是SimpleTcpCluster)会启动membership服务和Replication服务(用于建立tcp链接),membership服务记录了集群当前节点的信息,当一台节点接收http请求并产生一个新session时,调用Replication服务建立tcp连接把Session复制到membership列表

使用Apache + mod_jk + tomcat来实现tomcat集群的负载均衡出现的无法加载mod_jk.conf文件的问题

用Apache + mod_jk + tomcat来实现tomcat集群的负载均衡的 如果出现了问题,可以用cmd  cd到Apache安装文件的bin下,运行httpd文件,错误信息就会打印出来. 我这里出现的问题是  Include conf/mod_jk.conf无法加载该配置文件(英文翻译过来就是这个问题) 为什么呢? 经过反复的检查发现是我建立的关于mode_jk.conf文件跟work.properties文件格式不对, 经过检查,用文本文件创建了这两个文件之后,文件的后缀名都是.c