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 # 关闭 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.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/7fb57536500531a02c5b47b3805b162b.html