【问题标题】:Running Multiple Instances of Tomcat on same port在同一端口上运行多个 Tomcat 实例
【发布时间】:2014-11-23 10:57:08
【问题描述】:

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

【问题讨论】:

    标签: tomcat tomcat6 multiple-instances


    【解决方案1】:

    您可以使用 apache 网络服务器来实现这一点,该服务器基于使用 mod_jk 或 mod_proxy 的应用程序来引导请求。 (并获得两个扩展的解释)

    选择使用哪个 apache 扩展:apache to tomcat: mod_jk vs mod_proxy

    【讨论】:

    • 这就是要走的路!
    【解决方案2】:

    是的,你可以。在 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的war,webappsApp2目录和App2一样。

    在 App1 和 App2 的 dns zone 中放置服务器的公共 ip。

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

          是的,您可以在同一个端口上运行多个 tomcat(或任何其他对象)实例。 为此,您需要将多个 Real IP 绑定到 VIP,然后每个 RIP 都可以使用自己的一组端口进行侦听。

          因此,每个 tomcat 将在相同的端口上运行,但在不同的真实 IP 地址上运行。

          【讨论】:

            【解决方案6】:

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

              <!-- 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>
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2011-08-21
              • 2017-06-08
              • 1970-01-01
              • 1970-01-01
              • 2013-10-31
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多