linux服务器同时运行两个或多个tomcat

第一步:条件:配置好jdk,如果没有配置好请看:https://www.cnblogs.com/weibanggang/p/11460537.html

第二步:下载安装tomcat

下载tomcat到服务器中,并解压到文件夹,如/home/tomcat/tomcat1

再复制一份tomcat压缩包,解压到 /home/tomcat/tomcat2

如下是我的tomcat

复制命令:

cp -r /home/tomcat/tomcat8.5_1 /home/tomcat/tomcat8.5_2

 

第三步:配置tomcat环境变量(重点)

 同样是操作/etc/profile 文件。

#vi  /etc/profile

然后在文件最后一行,即刚刚添加JDK环境变量的后边添加如下配置:

#tomcat1
export CATALINA_HOME1=/home/tomcat/tomcat8.5_1
export CATALINA_BASE1=/home/tomcat/tomcat8.5_1
export TOMCAT_HOME1=/home/tomcat/tomcat8.5_1

#tomcat2
export CATALINA_HOME2=/home/tomcat/tomcat8.5_2
export CATALINA_BASE2=/home/tomcat/tomcat8.5_2
export TOMCAT_HOME2=/home/tomcat/tomcat8.5_2

#tomcat3
export CATALINA_HOME3=/home/tomcat/tomcat8.5_3
export CATALINA_BASE3=/home/tomcat/tomcat8.5_3
export TOMCAT_HOME3=/home/tomcat/tomcat8.5_3

#tomcat4
export CATALINA_HOME4=/home/tomcat/tomcat8.5_4
export CATALINA_BASE4=/home/tomcat/tomcat8.5_4
export TOMCAT_HOME4=/home/tomcat/tomcat8.5_4

#tomcat5
export CATALINA_HOME5=/home/tomcat/tomcat8.5_5
export CATALINA_BASE5=/home/tomcat/tomcat8.5_5
export TOMCAT_HOME5=/home/tomcat/tomcat8.5_5

#tomcat6
export CATALINA_HOME6=/home/tomcat/tomcat8.5_6
export CATALINA_BASE6=/home/tomcat/tomcat8.5_6
export TOMCAT_HOME6=/home/tomcat/tomcat8.5_6

(注意:tomcat123456中的配置命名)

添加后,ctrl+C, 然后命令行输入 :wq ,保存退出。加载环境变量,命名行:

source   /etc/profile 

配置成功!

第四步:修改tomcat123456中的server.xml文件(重点)

tomcat1和tomcat2配置如下:

  tomcat1:修改tomcat1的server.xml文件


1、修改Server prot 默认为8005--》修改为8001

<Server port="8001" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  -->

2、修改Connector port HTTP/1.1  默认为8080--》修改为80

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

3、修改Connector port AJP/1.3 默认为8009--》修改为8010

<!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

  tomcat2:修改tomcat2的server.xml文件

1、修改Server prot 默认为8005--》修改为8002
<Server port="8002" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html

2、修改Connector port HTTP/1.1  默认为8080--》修改为82

<Connector port="82" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

3、修改Connector port AJP/1.3 默认为8009--》修改为8011

 <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8011" protocol="AJP/1.3" redirectPort="8443" />

还有tomcat3456就不在这里演示,只需要根据以上配置,配置不能有重复的端口号

第五步:修改tomcat123456中的startup.sh 和 shutdown.sh文件(重点)

 

  tomcat1:修改tomcat1/bin/startup.sh 和 shutdown.sh 两个文件(同一代码HOME1)

1、tomcat1/bin/startup.sh

命令: vi tomcat8.5_1/bin/startup.sh
加入:
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=TOMCAT_HOME1


2、tomcat1/bin/shutdown.sh

命令: vi tomcat8.5_1/bin/shutdown.sh
加入:
export CATALINA_BASE=$CATALINA_BASE1
export CATALINA_HOME=$CATALINA_HOME1
export TOMCAT_HOME=TOMCAT_HOME1

  tomcat2:修改tomcat2/bin/startup.sh 和 shutdown.sh 两个文件(同一代码HOME2)

1、tomcat2/bin/startup.sh
命令: vi tomcat8.5_2/bin/startup.sh
加入:
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=TOMCAT_HOME2


2、tomcat2/bin/shutdown.sh
命令: vi tomcat8.5_2/bin/shutdown.sh
加入:
export CATALINA_BASE=$CATALINA_BASE2
export CATALINA_HOME=$CATALINA_HOME2
export TOMCAT_HOME=TOMCAT_HOME2

还有tomcat3456就不在这里演示,只需要对startup、shutdown 加入三行代码即可

最后:检验成果

分别启动tomcat中的 /bin/startup.sh ,然后打开浏览器访问测试。

 

 

 

posted @ 2019-09-04 18:43  韦邦杠  阅读(10371)  评论(0编辑  收藏  举报