Tomcat Administration
Tomcat 5, Tomcat 6, Tomcat 7 on platform such as Windows7, Solaris, Linux
This post is targeted for the Middleware admins, Tomcat Administrators, JEE developers and QA analysts. here I am discussing my experiments and understanding about Apache Tomcat Servlet Engine.
Tomcat Requirements
Tomcat software is freely available as zip distribution and it is in binary and source codes on Apache Tomcat site. Before you install Tomcat you must install JDK and configure it in the environment variables in profile or in Windows system variables.
Sun JDK 1.5 for Tomcat 5
Sun JDK1.6 for Tomcat 6
Sun JDK 1.6 or 7 for Tomcat 7
Operating Environment
In this post we are going to discuss about variety of operating systems such as Microsoft Windows 7, Oracle Solaris, Oracle/Redhat Linux.
Downloading Tomcat
You can have your own choice of selecting the versions but latest version will have more flexibility and bug fixes included.
For Windows 7 select 32bit or 64bit dependent zip files.
v
ery
When you download Tomcat 7.0.30 the file apache-tomcat-7.0.30-windows-x86.zip will be downloaded. Extract this to your root directory C:\ or D:\. For our flexibility, rename the folder name with move command.
c:\>move apache-tomcat-7.0.30 Tomcat7
1 dir(s) moved.
Setup the JAVA_HOME, CATALINA_HOME in the System properties of your Windows Control Panel as show in the following picture.
How to install Tomcat on Solaris?
1. Before installing tomcat make sure you set environment variable JAVA_HOME, JAVA_OPTS and CATALINA_HOME in .profile or If your default logon SHELL not bash then you run it thru command line then you must edit in the .bashrc or .bash_profile must have the two variables.
2. Download the latest tomcat installation file( apache-tomcat-5.5.17.tar.gz) and the Tomcat admin file(
apache-tomcat-5.5.17-admin.tar.gz) from the following location http://tomcat.apache.org/
3. Upload the installation file on the Solaris host, extract it contents using the following gunzip apache-tomcat-5.5.17.tar.gz into a folder /app/middleware/apache-tomcat-5.5.17., This will generate a tar file, use tar -xvf apache-tomcat-5.5.17.tar to extract the tar file to complete the installation process.
4. Similarly install the Tomcat Admin package.
5. Access the administration console the context path should be /admin
6. Starting the Tomcat server using startup.sh that is found in installation directory $CATALINA_HOME/bin.
7. Test the installation with http://localhost:8080 url, enter username admin password tomcat as default credentials. On successful installation following message will be displayed on the home page “If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!”
Troubleshooting Tomcat installation
1. If you are facing the an issue with admin user credentials, replace the content of CATALINA_HOME/conf/tomcat-users.xml with the below code.
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<!--
<role rolename="tomcat"/>
<role rolename="role1"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="role1" password="tomcat" roles="role1"/>
-->
<role rolename="manager"/>
<role rolename="admin"/>
<user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>
2. If you are see the following error while accessing the Tomcat server administration link “Tomcat's administration web application is no longer installed by default. Download and install the "admin" package to use it.” install the Tomcat admin package apache-tomcat-5.5.17-admin.tar if it is older version than 5 Here is the video tutorial by Gattu.
Tomcat directory structure:
bin: Contains all the server life-cycle scripts(start, shutdown etc.,) for both Windows and Linux.
common: Contains the main configuration files for Tomcat. The two most important are the server.xml and the global web.xml.
conf: Contains server configuration related files.
logs: All the server log files will stored in this folder
server: jsp servlet engine and java classes are stored in this folder
shared: Declare the classes and lib to specified number if applications
temp: temp files storage location
webapps: web application files are stored in it.
work: This is the directory in which Tomcat will place all servlets that are generated from JSPs. If you want to see exactly how a particular JSP is interpreted, look in this directory.
How you know the verion of Tomcat server?
1. Goto the Tomcat installation directory then bin execute the following command
./version.sh
Using CATALINA_BASE: /app/middleware/apache-tomcat-5.5.17
Using CATALINA_HOME: /app/middleware/apache-tomcat-5.5.17
Using CATALINA_TMPDIR: /app/middleware/apache-tomcat-5.5.17/temp
Using JRE_HOME: /usr/jdk/instances/jdk1.5.0
Server version: Apache Tomcat/5.5.17
Server built: Apr 14 2006 02:08:29
Server number: 5.5.17.0
OS Name: SunOS
OS Version: 5.10
Architecture: sparc
JVM Version: 1.5.0_28-b04
JVM Vendor: Sun Microsystems Inc.
How to stop the Running Tomcat server?
Goto the Tomcat installation path and bin, there you can see “shutdown.sh” script file, this will terminate the Tomcat server.
You can confirm this by check the java process. Identify the process id with the following command
ps -fu <user> |grep java
The command pargs will gives you the all the arguments that passed for a command or shell script
pargs 966
966: /usr/jdk/instances/jdk1.5.0/bin/java -Djava.util.logging.manager=org.apache.jul
argv[0]: /usr/jdk/instances/jdk1.5.0/bin/java
argv[1]: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
argv[2]: -Djava.util.logging.config.file=/app/middlewareapache-tomcat-5.5.17/conf/logging.properties
argv[3]: -Djava.endorsed.dirs=/app/middlewareapache-tomcat-5.5.17/common/endorsed
argv[4]: -classpath
argv[5]: :/app/middlewareapache-tomcat-5.5.17/bin/bootstrap.jar:/app/middlewareapache-tomcat-5.5.17/bin/commons-logging-api.jar
argv[6]: -Dcatalina.base=/app/middlewareapache-tomcat-5.5.17
argv[7]: -Dcatalina.home=/app/middlewareapache-tomcat-5.5.17
argv[8]: -Djava.io.tmpdir=/app/middlewareapache-tomcat-5.5.17/temp
argv[9]: org.apache.catalina.startup.Bootstrap
argv[10]: start
Access the Tomcat Server through the Web browser give the admin credentials
In the Left pane Select 'Administration' and click on the 'Status'link.
Where you can find the following details
1. JVM details
2. Thread details
3. Tomcat instance details
Deploying web applications on Tomcat
The deployment option is in different form. You have two options for deployment. 1. Exploded directory form, you need to provide Context Path (optional), XML Configuration file URL, Directory URL
1. In the http://localhost:8080/manager/ Scroll down the page to the section called "Deploy directory or WAR file located on server". Enter the context name preceded by "/" (e.g., /Calendar) in the "Context Path" field.
2. Leave the "XML Configuration file URL" filed blank.
3. Locate Calendar WAR file and enter its absolute name (e.g., /absolute/path/Calendar.war) in the "WAR or Directory URL" field.
2. Web Archive (war)
Deployment details of Tomcat server can be obtained from "Tomcat Web Application Manager"
This page will give you the list of the applications deployed on the Tomcat server.
1. Select Status from the left navigation bar of Tomcat home page
2. Select 'ListApplications' link on the manage page
3. Goto the bottom and in the 'WAR file to deploy' section click 'browse' button and locate your war file and click on 'Deploy' button
4. Now test your application with context path
Applications Details
Path -- Context path of your application
Display Name -- Name of your application
Running -- Lets you know the application status whether running or not
Sessions Current sessions count of the application
You have options to execute the following commands
Start to start the application when the application is stopped.
Stop Stop the application, when you access the application context path you will get the following message “HTTP Status 503 - This application is not currently available”
Reload Reloads the application with changes that you have made
Undeploy After the app has been stopped you can undeploy the app using 'undeploy'
Tomcat Book for free download only for Middleware Admin subscribers
Tomcat, The Definitive Guide, 2008 from Harshal Ladhe
Tomcat Book for download
Multiple Tomcat instances on a machine
In production environments we may need to setup this strategy to implement multiple Apache Tomcat instances. Details of how to do it is very clearly illustrated by Linux- Solutions blog: http://online-linux.blogspot.in/2011/02/how-to-configure-tomcat-in-linux.html
References