Saturday 26 January 2013

1) Secure the Manager Application

By default there are no users with the manager role. To make use of the manager webapp you need to add a new role and user into the $CATALINA_HOME/conf/tomcat-users.xml file.

<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>

2) Run the tomcat on different port

The most common hiccup is when another web server (or any process for that matter) has laid claim to port 8080.  This is the default HTTP port that Tomcat attempts to bind to at startup.  To change this, open the file:

$CATALINA_HOME/conf/server.xml

and search for '8080'.  Change it to a port that isn't in use, and is greater than 1024, as ports less than or equal to 1024 require superuser access to bind under UNIX.

Restart Tomcat and you're in business.  Be sure that you replace the "8080" in the URL you're using to access Tomcat.  For example, if you change the port to 1977, you would request the URL http://localhost:1977/ in your browser.

3) Remove Unnecessary Applications from the tomcat’s webapps directory


4) Increase serving capability of tomcat service

By default the tomcat can serve maximum 200 threads (i.e. 200 parallel request at a time) and if request exceeds 200 threshold it will maintain queue and managed internally. Depending on the machine hardware we can change the parameter “maxThreads” for port “8080” or “1977” in file:

$CATALINA_HOME/conf/server.xml

as

<Connector connectionTimeout="20000" maxThreads="400" port="1977" protocol="HTTP/1.1" redirectPort="8443"/>

5) Leverage Tomcat's shared library directory

If you're loading several applications with several of the same library dependencies, consider moving them from the applications' WEB-INF/lib directory to Tomcat's shared library $CATALINA_HOME/shared/lib. This will reduce the memory used by each application and result in smaller WAR files.

6) Increase the Heap Size of Tomcat

Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,

set CATALINA_OPTS=”-Xms512m -Xmx1024m” (Windows)
export CATALINA_OPTS=”-Xms512m -Xmx1024m” (ksh/bash)
setenv CATALINA_OPTS “-Xms512m -Xmx1024m” (tcsh/csh)

Minimum Heap Size will be used - 512 mb
Maximum Heap Size will be used - 1024 mb

In catalina.bat or catalina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options. What is the difference between CATALINA_OPTS and JAVA_OPTS? The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don’t want Tomcat to inadvertently pick up the JVM options intended for other apps. So better to change CATALINA_OPTS.
Categories: , , , ,

1 comment:

Find me on Facebook! Follow me on Twitter!