centos6.5下安装zip格式的tomcat7和tomcat8,并同时运行

前提:

我的tomcat7安装在

  /home/hadoop/software/apache-tomcat-7.0.69,

tomcat8安装在

  /home/hadoop/software/apache-tomcat-8.0.37

首先在/etc/profile的最后添加:

##多个tomcat的配置
CATALINA_BASE=/home/hadoop/software/apache-tomcat-7.0.69
CATALINA_HOME=/home/hadoop/software/apache-tomcat-7.0.69
export CATALINA_BASE CATALINA_HOME
CATALINA_2_BASE=/home/hadoop/software/apache-tomcat-8.0.37
CATALINA_2_HOME=/home/hadoop/software/apache-tomcat-8.0.37
export CATALINA_2_BASE CATALINA_2_HOME
TOMCAT_HOME=/home/hadoop/software/apache-tomcat-7.0.69
export TOMCAT_HOME
TOMCAT_2_HOME=/home/hadoop/software/apache-tomcat-8.0.37
export TOMCAT_2_HOME

 

然后修改各自的bin下的startup.sh和shutdown.sh,在开始处添加如下两行代码:

(由/etc/profile文件的设置可知,tomcat7设置了CATALINA_HOME和CATALINA_BASE,tomcat8设置了CATALINA_2_HOME和CATALINA_2_BASE

所以各自的文件中对应各自的设置(如下是tomcat8的设置)

export CATALINA_HOME=$CATALINA_2_HOME
export CATALINA_BASE=$CATALINA_2_BASE

最后,需要修改启动、停止端口号,否则会出现端口号的冲突(我设置的时候tomcat8端口未修改,只修改了tomcat7的端口)。

打开conf/server.xml,我的修改如下:将shutdown端口改为9005,启动端口为9999,AJP/1.3的启动端口为9009

<Server port="9005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <Listener className="org.apache.catalina.core.JasperListener" />
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
  <GlobalNamingResources>
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
  <Service name="Catalina">
    <Connector port="9999" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="UTF-8"/>
    <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" />
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

 

上述全部完成之后重启电脑。然后分别启动两个tomcat,就能同时运行了。

 

备注:centos启动mysql服务的方法:service mysqld start/stop

  

posted @ 2016-09-23 13:51  博学善思。。ljd  阅读(933)  评论(0编辑  收藏  举报