一、Tomcat多实例
Tomcat多实例是指在同一台服务器上运行多个独立的tomcat实例,每个tomcat实例都具有独立的配置文件、日志文件、应用程序和端口,通过配置不同的端口和文件目录,可以实现同时运行多个独立的Tomcat服务器,每个服务器都可以独立处理用户的请求,这样可以提高服务器的并发处理能力和灵活性,同时隔离不同的应用程序和配置
1.配置tomcat多实例
修改tomcat主配置文件server.xml中的三个端口号8080、8005、8009
修改tomcat启动停止脚本startup.sh、shutdown.sh添加export CATALINA BASE CATALINA HONE TOWCAT HOME变量都指向实例的工作目录
2.安装tomcat(需装jdk,这里上篇博客已装)
#创建tomcat文件夹(如已创建请无视)
mkdir /usr/local/tomcat
#实例1
mv apache-tomcat-9.0.16 /usr/local/tomcat/tomcat1
#实例2
cp -a /usr/local/tomcat/tomcat1 /usr/local/tomcat/tomcat2
#实例3
cp -a /usr/local/tomcat/tomcat1 /usr/lcoal/tomcat/tomcat3
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
#tomcat3
export CATALINA_HOME3=/usr/local/tomcat/tomcat3
export CATALINA_BASE3=/usr/local/tomcat/tomcat3
export TOMCAT_HOME3=/usr/local/tomcat/tomcat3
source /etc/profile.d/tomcat.sh
4.修改端口号
第一个连接器默认监听8080端口,负责建立HTTP连接。在通过浏览器访问Tomcat服务器的Web应用时,使用的就是这个连接器
第二个连接器默认监听8009端口,AJP端口,即容器使用,如Apache能通过AJP协议访问Tomcat的8009端口
#tomcat2
vim /usr/local/tomcat/tomcat2/conf/server.xml
#22行,修改Server prot,默认为8005 -> 修改为8006
#69行,修改Connector port,HTTP/1.1 默认为8080 -> 修改为8081
#116行,修改Connector port AJP/1.3,默认为8009 -> 修改为8010
#tomcat3
vim /usr/local/tomcat/tomcat3/conf/server.xml
#22行,修改Server prot,默认为8005 -> 修改为8007
#69行,修改Connector port,HTTP/1.1 默认为8080 -> 修改为8082
#116行,修改Connector port AJP/1.3,默认为8009 -> 修改为8011
5.修改各个tomcat实例中的startup.sh和shutdown.sh文件,添加tomcat环境变量
#tomcat1
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
#tomcat2
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
#tomcat3
vim /usr/local/tomcat/tomcat3/bin/startup.sh
export CATALINA_BASE=$CATALINA_BASE3
export CATALINA_HOME=$CATALINA_HOME3
export TOMCAT_HOME=$TOMCAT_HOME3
vim /usr/local/tomcat/tomcat3/bin/shutdown.sh
export CATALINA_BASE=$CATALINA_BASE3
export CATALINA_HOME=$CATALINA_HOME3
export TOMCAT_HOME=$TOMCAT_HOME3
tomcat1、2、3全部都要设置
6.启动各tomcat中的/bin/startup.sh
#后台启动
/usr/local/tomcat/tomcat1/bin/startup.sh
/usr/local/tomcat/tomcat2/bin/startup.sh
/usr/local/tomcat/tomcat3/bin/startup.sh
ss -natp |grep java
7.浏览器访问测试
tomcat多实例配置成功