Running Multiple Instances of Tomcat on same port

泄露秘密 提交于 2019-12-22 10:37:06

问题


I need to run multiple instances of tomcat6 under different directory names on the same port. I will install tomcat6 twice for two different projects. But how to configure both the instances to run on the same port?


回答1:


You could realise this using an apache webserver that is directing the requests based on the application using mod_jk or mod_proxy. (and get an explanation on both extensions)

To choose which apache extension to use: apache to tomcat: mod_jk vs mod_proxy




回答2:


Yes, you can. In server.xml replace:

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

By

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

In the webappsApp1 directory you put the war of App1, the same for webappsApp2 directory and App2.

In dns zone of App1 and App2 put the public ip of the server.




回答3:


Its impossible to run two service to serve via single port. You can only run one tomcat per port number.




回答4:


Only one process can listen at a certain port at a time. So what you want to do is not directly possible. You may have luck with forwarding requests to the other instance, or using another server as front end (for example Apache).




回答5:


Yes you can run multiple instances of tomcat ( or any other object ) on same port. For this you need to have multiple Real IP bounded to VIP and then each RIP can use their own set of port to listen.

So, each tomcat will run on same port but on different Real IP address.




回答6:


Different Instances with different Context with Same port number:

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


来源:https://stackoverflow.com/questions/26093298/running-multiple-instances-of-tomcat-on-same-port

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!