Linux下多tomcat部署

为了充分利用资源,可以在一台服务器下运行多个tomcat

step1:配置环境变量

export JAVA_HOME=/opt/jdk8
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

#tomcat8
export CATALINA_8_BASE=/opt/tomcat8
export CATALINA_8_HOME=/opt/tomcat8
export TOMCAT_8_HOME=/opt/tomcat8

#tomcat1
export CATALINA_1_BASE=/opt/tomcat1
export CATALINA_1_HOME=/opt/tomcat1
export TOMCAT_1_HOME=/opt/tomcat1
#tomcat2
export CATALINA_2_BASE=/opt/tomcat2
export CATALINA_2_HOME=/opt/tomcat2
export TOMCAT_2_HOME=/opt/tomcat2

 使环境变量立即生效:

source /etc/profile

step2:修改各tomcat startup、shutdown获取环境变量

   vim tomcat1/bin/startup.sh  

   vim tomcat1/bin/shutdown.sh

export CATALINA_HOME=$CATALINA_1_HOME
export CATALINA_BASE=$CATALINA_1_BASE

 其它以此类推

step3:修改服务端口

vim tomcat1/conf/server.xml

使Server port、Connector port http1.1、Connector port AJP端口与其它tomcat各不相同即可

如tomcat1:

<Server port="7005" shutdown="SHUTDOWN">
 <Connector port="8080" protocol="HTTP/1.1"
              connectionTimeout="20000"
               redirectPort="8443" />
<Connector port="7009" protocol="AJP/1.3" redirectPort="8443" />

 tomcat2:

<Server port="9005" shutdown="SHUTDOWN">
<Connector port="9090" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />

step4:启动试试吧

相关推荐