Tomcat 的 多实例
1 安装 jdk
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
cd /opt
rpm -ivh jdk-8u201-linux-x64.rpm
rpm -qpl jdk-8u201-linux-x64.rpm
vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar
export PATH=$JAVA_HOME/bin/:$PATH
source /etc/profile.d/java.sh
2 安装启tomcat
cd /opt/
tar -zxvf apache-tomcat-9.0.16.tar.gz
mkdir /usr/lcoal/tomcat
mv apache-tomcat-9.0.16 /usr/local/tomcat1
cp -a /usr/local/tomcat/tomcat1 /usr/local/tomcat/tomcat2 #直接复制tomcat1 目录
3 配置tomcat 环境变量
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
source /etc/profile.d/tomcat.sh
4 修改 tomcat2 的主配置文件,让 各tomcat 实例配置不能有重复端口号
#tomcat1 配置保持不动。修改tomcat2 主配置文件
vim /usr/local/tomcat/tomcat2/conf/server.xml
--- 第22行Server port,从8005改为监听8006
<Server port"8006" shutdown="SHUTDOWN">
---- 第69 行 Connector port HTTP/1.1 由 8080 改为8081 ,此端口负责建立http连接
<Connector port="8081" protocol="HTTP/1.1"
----第 116 行 Connector port AJP/1.3 由 8009 改为 8010,此端口负责和其他http服务器建立连接
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443"
5 修改tomcat 实例中的startup.sh 和 shutdown.sh文件,添加tomcat环境变量
vim /usr/local/tomcat/tomcat1/bin/startup.sh
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1
vim /usr/local/tomcat/tomcat1/bin/shutdown.sh
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=$TOMCAT_HOME1
vim /usr/local/tomcat/tomcat2/bin/startup.sh
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2
vim /usr/local/tomcat/tomcat2/bin/shutdown.sh
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=$TOMCAT_HOME2
6 启动服务测试
/usr/local/tomcat/tomcat1/bin/startup.sh
/usr/local/tomcat/tomcat2/bin/startup.sh
netstat -natp | grep java
firefox http://192.168.23.103:8080
firefox http://192.168.23.103:8081