一台机器同时运行两个或多个Tomcat

一台机器同时运行两个或多个Tomcat


今天经理交给我一个任务,让我在服务器上再装一个测试用的tomcat,因为我们的系统中有用到调用移动CMPP短信接口给客户发短信的功能,限制了IP,只能在服务器上调试。没辙,以前也想过在自己的机器上同时跑两个tomcat,以为只要改一下端口号就没问题,其实这只是其中的一步而已。

当第一个tomcat启动后,后面tomcat的server.xml中的端口不管怎么改,仍然会报端口冲突。后来在dos下运行才发现所有的tomcat都会去找

CATALINA_HOME和CATALINA_BASE这两个环境变量,因此步骤如下: 
1.使用压缩版的tomcat不能使用安装版的。 
2.第一个tomcat的配置不变。 
3.增加环境变量CATALINA_HOME2,值为新的tomcat的地址;增加环境变量CATALINA_BASE2,值为新的tomcat的地址。 
4.修改新的tomcat中的startup.bat,把其中的CATALINA_HOME改为CATALINA_HOME2。 
5.修改新的tomcat中的catalina.bat,把其中的CATALINA_HOME改为CATALINA_HOME2,CATALINA_BASE改为CATALINA_BASE2。 
6.修改conf/server.xml文件: 
6.1 <Server port="8005" shutdown="SHUTDOWN">把端口改为没有是使用的端口。 
6.2 <Connector port="8080" maxHttpHeaderSize="8192" 
  maxThreads="150" minSpareThreads="25" maxSpareThreads="75" 
  enableLookups="false" redirectPort="8443" acceptCount="100" 
  connectionTimeout="20000" disableUploadTimeout="true" /> 把端口改为没有是使用的端口。 
6.3<Connector port="8009" 
  enableLookups="false" redirectPort="8443" protocol="AJP/1.3" /> 把端口改为没有是使用的端口。 
7成功!

下面是我配置好的server.xml

<?xml version='1.0' encoding='utf-8'?>
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
     8005->8007
 -->
<Server port="8007" shutdown="SHUTDOWN">
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  <Listener className="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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">
    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL HTTP/1.1 Connector on port 8080->8090
    -->
    <Connector port="8090" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

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

    <Engine name="Catalina" defaultHost="localhost">

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <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 "%r" %s %b" />

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


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭