Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,互不影响。多实例与虚拟主机不同,虚拟主机的本质是在一个服务下有多个相对独立的目录,但是多实例却存在了多个服务。
实验IP:20.0.0.55
Tomcat实例1开放端口:8080、8005、8009
Tomcat实例2开放端口:8081、8006、8010
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
cd /opt
rpm -qpl jdk-8u201-linux-x64.rpm #查询指定软件包的文件列表
rpm -ivh jdk-8u201-linux-x64.rpm #安装软件包,显示详细信息
java -version #查看java版本
cd /opt
tar zxvf apache-tomcat-9.0.16.tar.gz
mkdir /usr/local/tomcat
mv apache-tomcat-9.0.16 /usr/local/tomcat/tomcat1
cp -a /usr/local/tomcat/tomcat1 /usr/local/tomcat/tomcat2 #递归复制,连属性一起
vim /etc/profile.d/tomcat.sh
#tomcat1
export CATALINA_HOME1=/usr/local/tomcat/tomcat1
export CATALINA_BASE1=/usr/local/tomcat/tomcat1
export TOMCAT_HOME1=/usr/local/tomcat/tomcat1
#tomcat2
export CATALINA_HOME2=/usr/local/tomcat/tomcat2
export CATALINA_BASE2=/usr/local/tomcat/tomcat2
export TOMCAT_HOME2=/usr/local/tomcat/tomcat2
--->:wq
source /etc/profile.d/tomcat.sh
cp /usr/local/tomcat/tomcat2/conf/server.xml /usr/local/tomcat/tomc
at2/conf/server.xml.bak #备份
vim /usr/local/tomcat/tomcat2/conf/server.xml
#22行,修改Server prot,默认为8005 -> 修改为8006
修改为8081
#116行,修改Connector port AJP/1.3,默认为8009 -> 修改为8010
第一个连接器默认监听8080端口,负责建立HTTP连接。在通过浏览器访问Tomcat服务器的Web应用时,使用的就是这个连接器。
第二个连接器默认监听8009端口,负责和其他的HTTP服务器建立连接。在把Tomcat与其他HTTP服务器集成时,就需要用到这个连接器。
vim /usr/local/tomcat/tomcat1/bin/startup.sh
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
##添加以下内容
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1
vim /usr/local/tomcat/tomcat1/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1
vim /usr/local/tomcat/tomcat2/bin/startup.sh
# -----------------------------------------------------------------------------
# Start Script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2
vim /usr/local/tomcat/tomcat2/bin/shutdown.sh
# -----------------------------------------------------------------------------
# Stop script for the CATALINA Server
# -----------------------------------------------------------------------------
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2
/usr/local/tomcat/tomcat1/bin/startup.sh
/usr/local/tomcat/tomcat2/bin/startup.sh
netstat -natp | grep java
http://20.0.0.55:8080
http://20.0.0.55:8081
mg-oAkUf9ei-1659073707212)]
http://20.0.0.55:8080
http://20.0.0.55:8081
[外链图片转存中…(img-YBP3Hv0v-1659073707212)]