wood burning stoves*
The moose likes Tomcat and the fly likes How to set a different port number to for Tomcat 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to set a different port number to for Tomcat 6" Watch "How to set a different port number to for Tomcat 6" New topic
Author

How to set a different port number to for Tomcat 6

Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99
Hi
Am have Tomcat4 and Tomcat6 installed on my hp-Unix machine,

Tomcat 4 is running fine with port 8080, now i have changed the port number for tomcat6 as

but this doesn't work, i cant run both the servers at one time.

I have done this as i nee two different instances of tomcat.
One more problem here is, if i shut one server down the other is also getting down.
Please let me know, how can i change the port number. and how to use two instances at same time.

SCJP 1.5
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Bharadwaj,

"it does not work" is not a good problem description.

You need to change the other ports as well. Hunt around in server.xml to find all ports your server uses and change each of them to a new, free value.


Java-monitor, JVM monitoring made easy <- right here on Java Ranch
Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99
I have changed the ports in server.xml, but same problem persists.
Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99
I think this may be due to the cataliana_home variable,
how can we set the catalina_home for different instances of the tomcat on one unix machine.
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Bharadwaj,

Please post the error you are getting. To set the CATALINA_HOME variable, use (in bash) "export CATALINA_HOME=somepath".
Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99


This is the error am getting when i've set the path as
export CATALINA_HOME=/usr/tomcat/Tomcat4
export CATALINA_BASE=/usr/tomcat/Tomcat4

Am i doing any thing wrong?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

You cannot just "Change the Tomcat Port". Tomcat uses something like 5 separate ports - one for HTTP, one for HTTPS, one for ajp, one for control, and probably one or two I've forgotten.

It's a fundamental architectural restriction that only one process can listen on a TCP/IP port at a time, so you not only have to change the base port, you have to change all the ports in the server.xml file to be ports that no other app on the server is using - even the non-Tomcat apps.


Customer surveys are for companies who didn't pay proper attention to begin with.
Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99
Now am able to change the port number,
I have changed the catalina_home and base, this is working now.

But the problem am facing is, as i have 2 instances of tomcat, i have to declare the catalina_home variable for these two instances. how can i do it differently for these two instances?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

There are 2 Catalina environment variables. One is CATALINA_HOME and one is CATALINA_BASE and they're intended for exactly what you're trying to do.

I can never remember which is which. This is one of those items that litter technical exams when in the real world, it's done so rarely I simply RTFM and save my memory for stuff that's actually critical day-to-day <snark/>. So I'll recommend that you do likewise - which also means that you'll be looking at the exact way it's handled on the version of Tomcat that you're interested in.

What's more important to know is that Tomcat is designed with a sharable core and per-instance environments. That is, all the Tomcat instances would have common bin and lib directories, but each instance would have its own private webapps, conf, and log directories.

For most purposes, CATALINA_HOME and CATALINA_BASE will point to the same directory. In your case, you would have distinct values for them.

For example server1 (tomcat_A):

CATALINA_HOME=/usr/local/apache-tomcat-6.0
CATALINA_BASE=/var/tomcat_A
$CATALINA_HOME/bin/catalina.sh start

Server2 (tomcat_B):

CATALINA_HOME=/usr/local/apache-tomcat-6.0
CATALINA_BASE=/var/tomcat_B
$CATALINA_HOME/bin/catalina.sh start

Like I said, I get HOME and BASE confused, so you may have to swap them.

This is how you'd do it for Unix-like systems. I haven't looked at what it takes for Windows, but the same rules apply. You'd just have to allow for how Windows manages environment variables.
Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99
Thanks a TON Tim ..

But i have a question here, when i want to start one instance say TomcatA, then the other instance TomcatB also starts, even both instances would stop at a time when i run shutdown.sh .
I want to start and stop the two instances independently. How can this be done?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

That should be determined by which set of enviroment settings you're using.

I haven't actually looked into it, but what I'd expect is that the server.xml for the CATALINA_BASE would be read and the stop signal would be sent to that Tomcat's control port.

Something like that obviously happens even on a single-instance setup when you define alternate ports, so why tamper with success?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12809
    
    5
Each tomcat instance must be given its own control port in addition to the port to listen for requests - see server.xml.

Bill

Bharadwaj Adepu
Ranch Hand

Joined: Dec 30, 2007
Posts: 99
Hi All
Thanks a lot for your Help..!!
Now am able to boot the two instances of the tomcat independently, and both are up and running.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set a different port number to for Tomcat 6