• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Two Tomcat Instances - multiple IPs - Single Port

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I apologise if this has been answered previously. I searched but could not find it.

I am running Windows Server 2008 R2.
I would like to run two Tomcat instances (6.0.x and 7.0.x) Each instance would have multiple sites, each with its own IP address, but all listening on Port 8080.
Is this possible?

For more details, see below:



CURRENT CONFIG (This works fine. We have this sort of configuration set up on multiple website already):

Tomcat 6.0.39

server.xml (key items, not all)
<Server port="8005" shutdown="SHUTDOWN">
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="conf/keystore" keystorePass="password" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> </Host>
<Host name="10.0.0.1" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>website1.domain.com</Alias> <Context path="" docBase="website1" debug="5" reloadable="true" crossContext="true"/> </Host>
<Host name="10.0.0.2" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>website2.domain.com</Alias> <Context path="" docBase="website2" debug="5" reloadable="true" crossContext="true"/> </Host>
<Host name="10.0.0.3" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>website3.domain.com</Alias> <Context path="" docBase="website3" debug="5" reloadable="true" crossContext="true"/> </Host>




REQUIRED CONFIG

Tomcat 6.0.39

server.xml (As above)
I'm assuming I will need to add something to the Server Port and Connector Port entries to specify which IP addresses to listen to?
And, possible delete the <host name = localhost ...> line?


Tomcat 7.0.54

server.xml
I'm assuming it will need to have a similar configuration as above, but specifying the new IP addresses (10.0.0.4 and 10.0.0.5)




I will try to do some more research and see if I can scrape together a test box to try this out on first, but was hoping someone may know this off the top of their heads

As always, I'm more than happy to provide more info if required. Tomcat is not my strong area, so I have possibly forgotten some crucial info.
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your OS won't allow you to start two tomcat instances on one port. You could have a webserver running on 8080 and make that forward requests to either of the tomcat instances started on different ports.
 
Bartender
Posts: 20842
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, no OS I know allows ANY application to use a tcp/ip port that some other application is listening on.

That's because although you can tell a port what IP addresses to listen on, the port itself must be unique within the OS.

You'll have better luck putting a front-end application ahead of your Tomcat instance and having that application re-route or proxy to the appropriate Tomcat, based on the URL. Each Tomcat would have to have its own unique port settings (as specified in the server.xml file), but then you'd have a single place for incoming requests (and a single port, if that pleases you). You'd simply set up the routing rules in your front-end web server.

You have a wide choice of available front-ends, including IIS, Apache HTTPD, Squid, and so forth. Basically, any application that can proxy and has user-definable URL rules.
 
Anthony Green
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I think I have got this working.
It was more the same port that I was hoping to listen on. I would have different IPs.

This is the configuration I have now, and I can load all the websites.
The Server Port is the only one (that I can see) that I cannot apply an address attribute to.
Can anyone see any issues with this?
It does seem to work, but there could be some other concerns I'm not aware of.


Tomcat 6.0.39

server.xml (key items, not all)
<Server port="8005" shutdown="SHUTDOWN"> <<-- NEED TO CHANGE THIS PORT FOR EACH TOMCAT INSTANCE
<Connector address="10.0.0.1" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" />
<Connector address="10.0.0.2" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" />
<Connector address="10.0.0.1" port="8009" protocol="AJP/1.3" />
<Connector address="10.0.0.2" port="8009" protocol="AJP/1.3" />
<Engine name="Catalina" defaultHost="10.0.0.10">
<Host name="10.0.0.10" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> </Host>
<Host name="10.0.0.1" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>website1.domain.com</Alias> <Context path="" docBase="website1" debug="5" reloadable="true" crossContext="true"/> </Host>
<Host name="10.0.0.2" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>website2.domain.com</Alias> <Context path="" docBase="website2" debug="5" reloadable="true" crossContext="true"/> </Host>


Tomcat 7.0.54

server.xml (key items, not all)
<Server port="8006" shutdown="SHUTDOWN"> <<-- NEED TO CHANGE THIS PORT FOR EACH TOMCAT INSTANCE
<Connector address="10.0.0.3" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" />
<Connector address="10.0.0.4" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" />
<Connector address="10.0.0.3" port="8009" protocol="AJP/1.3" />
<Connector address="10.0.0.4" port="8009" protocol="AJP/1.3" />
<Engine name="Catalina" defaultHost="10.0.0.11">
<Host name="10.0.0.11" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> </Host>
<Host name="10.0.0.3" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>website3.domain.com</Alias> <Context path="" docBase="website3" debug="5" reloadable="true" crossContext="true"/> </Host>
<Host name="10.0.0.4" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Alias>website4.domain.com</Alias> <Context path="" docBase="website4" debug="5" reloadable="true" crossContext="true"/> </Host>
 
Tim Holloway
Bartender
Posts: 20842
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't work that way.

If you start multiple Tomcat instances and they're attempting to listen on the same port number (regardless of the IP address), the second and subsequent Tomcats will start, but they won't be able to listen on the previously-claimed ports, so they'll just sit there and be useless. You'll see an error message in the log.

If you define multiple Connector IP addresses, the Tomcat will listen on ALL Connector IPs, and a request for any webapp can be made to any IP address. There will be no routing by IP. Tomcat routes by URL.

The reason that the Control port isn't allowed multiple instances is that it is the Control port for Tomcat. General requests don't come in to that port, only Tomcat control packets.
 
Anthony Green
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim.

Both Tomcat instances do work (I can view the websites), but I'm assuming that is only because I have static test pages.
If I was to start using Java apps etc, is that when I would notice problems?

Sorry for all the questions, but I am new to Tomcat, so appreciate all the information I can get

In the meantime, I will locate another web server to install the second Tomcat instance on.

 
Tim Holloway
Bartender
Posts: 20842
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can run multiple instances of Tomcat on a single machine. In fact, that's why there's a CATALINA_HOME and a CATALINA_BASE environment variables - so you can run multiple copies of Tomcat from a single set of Tomcat runtimes.

What you cannot do is have multiple applications listening to the same TCP/IP port. That's not a Tomcat limitation, it's a TCP/IP restriction.

So to run multiple Tomcat instances, you'd have a separate CATALINA_BASE directories, each with its own conf subdirectory containing a server.xml set with ports used by that copy of Tomcat and no other.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!