Thursday, 23 April 2009
Wednesday, 15 April 2009
Tomcat configuration: multi hosting

In order to set a multi host we need to act on server.xml (in a standard Tomcat installation you can find it in CATALINA_HOME/conf) and change some parameters.
The default form of parameters that we want to change is:

In this example there is a single host and it's localhost and its appBase is in the default Tomcat location webapps directory.
For ours settings we add our virtual host:

In this case the default Host is the same as before, localhost, but we added a new host "demo.twproject.com" and we specified the appBase that is different from Tomcat's default location. But notice that this setting is not enough to set a new virtual host: we have to create (if it doesn't exist you must create it ) an xml context file relative to our new host under
'CATALINA_HOME/conf/Catalina/hostName'.
You can notice that directory structure has a correspondence with the engine and host name, if you want to be more general you should write structure for virtual hosts as
'CATALINA_HOME/conf/EngineName/virtualHostName'
In our specific case the application 'demo.twproject.com' has to answer as root of our registered url, so we created a context file named 'ROOT.xml' under
'CATALINA_HOME/conf/Catalina/demo.twproject.com/',
and the context is:

In this way we can set more virtual hosts that respond to different urls.
We set max and min Java heap size allocation using 'tomcat6w.exe', as we are on a Windows server (but what we’ve done before is valid in general) and set max and min at the same size, so we can allocate definitely a portion of memory for the JVM. For other settings such as GC optimized for multiprocessor machines, policy for scavengers, optimizations for throughput we have set a system variable named CATALINA_OPTS with our configuration:
CATALINA_OPTS = -Xmn 600m -XX:-UseParallelOldGC -XX:+AggressiveOpts
In other systems like Linux we can set max and min java heap size adding to CATALINA_OPTS parameters -Xmx and -Xms with max and min heap size.
As web-applications manage utility we use Lambda probe, a useful tool for managing multiple web apps and get statistics on them and on the system:

Lambda Probe is easy to install on your Tomcat ( or other application-server ), because it is just a war that you deploy in your app-server.
References
Java
http://java.sun.com/performance/reference/whitepapers/tuning.html#section4.2.5
http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp
http://java.sun.com/docs/hotspot/gc5.0/gc_tuning_5.html
Tomcat 6
http://tomcat.apache.org/tomcat-6.0-doc/deployer-howto.html#A%20word%20on%20Contexts
http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
Lambda Probe
http://www.lambdaprobe.org/d/index.htm
@author Roberto Baldi and Pietro Polsinelli
Labels:
Tomcat multi host,
Tomcat vistual host
Subscribe to:
Posts (Atom)