在同一端口上运行Tomcat的多个实例

时间:2014-09-29 05:53:46

标签: tomcat tomcat6 multiple-instances

我需要在同一端口上的不同目录名下运行多个tomcat6实例。我将为两个不同的项目安装两次tomcat6。但是如何配置两个实例在同一个端口上运行?

5 个答案:

答案 0 :(得分:4)

您可以使用apache webserver实现这一点,该服务器使用mod_jk或mod_proxy根据应用程序指导请求。 (并获得两个扩展的解释)

选择要使用的apache扩展名:apache to tomcat: mod_jk vs mod_proxy

答案 1 :(得分:3)

是的,你可以。在server.xml中替换:

<Host name="localhost"  appBase="webapps" unpackWARs="true" autoDeploy="true">
    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->
    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <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>

通过

<Host name="app1.com"  appBase="webappsApp1" unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <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>

<Host name="app2.com"  appBase="webappsApp2" unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <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>

在webappsApp1目录中你输入了App1的战争,对于webappsApp2目录和App2也是如此。

在App1和App2的dns区域中放入服务器的公共IP。

答案 2 :(得分:1)

通过单端口运行两个服务是不可能的。每个端口号只能运行一个tomcat。

答案 3 :(得分:1)

一次只能有一个进程可以侦听某个端口。所以你想做的事情不是直接可能的。您可以将转发请求转发给其他实例,或者使用其他服务器作为前端(例如Apache)。

答案 4 :(得分:0)

具有相同端口号的不同上下文的不同实例:

  <!-- Test1 -->
  <Host name="192.168.1.254"  appBase="webapps"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Context docBase="Testing" path="/" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="254_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

  <!-- Test2 -->
  <Host name="192.168.1.250"  appBase="webapps1"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Context docBase="Testing2" path="/" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="250_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>

  <!-- Test3 -->

  <Host name="192.168.1.249"  appBase="webapps2"
        unpackWARs="true" autoDeploy="true">

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Context docBase="Testing3" path="/" reloadable="true"/>
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="249_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

  </Host>