Tomcat
Tomcat
Tomcat
Stephen Bee
All trademarks used herein are
the sole property of their
respective owners.
What is Tomcat?
A Java driven Web Application Server
− http://tomcat.apache.org/
Provides support for Java web applications
− JSP Documents
− WAR (Web Application aRchive) files
Has a self-contained HTTP server
The course of a Tomcat request
Browser Client
Tomcat Server
JVM
Benefits (and down falls) of Tomcat
Easy to install
JVM and application libraries are pre-loaded
– Pro: Things only need to be compiled once
– Con: Requires a hefty chunk of memory
Installation
Installation Requirements
http://server.example.com:8080/jsp-examples/
What's Installed?
What's Installed?
jsvc
client Apache
Tomcat
Start up :: jsvc :: Logging
Logs to /usr/local/jakarta/tomcat/logs/catalina.out
Three log levels exist: SEVERE, WARNING, and INFO
[Opened /usr/local/jdk1.6.0_02/jre/lib/rt.jar]
[Loaded java.lang.Object from /usr/local/jdk1.6.0_02/jre/lib/rt.jar]
[Loaded java.io.Serializable from /usr/local/jdk1.6.0_02/jre/lib/rt.jar]
[Loaded java.lang.Comparable from /usr/local/jdk1.6.0_02/jre/lib/rt.jar]
[Loaded java.lang.CharSequence from /usr/local/jdk1.6.0_02/jre/lib/rt.jar]
[Loaded java.lang.String from /usr/local/jdk1.6.0_02/jre/lib/rt.jar]
...... truncated .....
Start up :: Auto Deploying Applications
By default, all WAR files are automatically deployed at start up
− Can be disabled on a per-host basis with the
deployOnStartup attribute
Loaded org.apache.catalina.startup.HostConfig
DeployedApplication from file:/usr/local/jakarta/apache-tomcat-5.5.25/server/lib/catalina.jar
May 22, 2008 5:12:48 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive example.war
Start up :: Knowing when it's completed
Pre-loading all libraries can take quite some time
Applications will be inaccessible until pre-loading completes
Start time in catalina.out indicates that start up has completed
-Xmx200M
-Xms100M
<Server>
<Service name=”Catalina”>
<Connector port=”8080” ... /> <Connector port=”8009” ... />
<Engine name=”Catalina” defaultHost=”localhost”>
Host
Host
<Host name=”tomcat.com” appBase=”/home/tomcat/public_html”>
<Alias>www.tomcat.com</Alias>
<Context path=”” reloadable=”true” docBase=”/home/tomcat/public_html”>
</Host>
http://tomcat.apache.org/tomcat-5.5-doc/config/index.html
Configuration :: Connectors
Facilitates communication between applications and the clients
Each Connector creates a worker process with a unique port
Module Documentation:
http://tomcat.apache.org/connectors-doc/reference/apache.html
Front End :: Module Configuration
/usr/local/apache/conf/httpd.conf
LoadModule jk_module modules/mod_jk.so
/usr/local/apache/conf/jk.conf
JkWorkersFile /usr/local/jakarta/tomcat/conf/workers.properties
JkLogFile /usr/local/apache/logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
Front End :: workers.properties
Defines parameters for communicating with Tomcat workers
Multiple workers can be defined, if required.
/usr/local/jakarta/tomcat/conf/workers.properties
workers.tomcat_home=/usr/local/jakarta/tomcat
workers.java_home=/usr/local/jdk/jre
worker.list=ajp12, ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
Front End :: Site Configuration
Site configurations are included from the Apache userdata directories
<VirtualHost 10.0.0.1:80>
ServerName tomcat.com
.....
Include "/usr/local/apache/conf/userdata/std/2/tom/tomcat.com/*.conf"
</VirtualHost>
Front End :: cp_jkmount.conf
Example Configuration
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
</IfModule>
Front End :: mod_jk.log
Useful for troubleshooting communication failures with mod_jk
Log levels can be adjusted in /usr/local/apache/conf/jk.conf
− http://tomcat.apache.org/connectors-doc/reference/apache.html
ajp_service::jk_ajp_common.c (2046): (ajp13) receiving from tomcat failed, recoverable operation attempt=0
ajp_connect_to_endpoint::jk_ajp_common.c (891): Failed opening socket to (127.0.0.1:8009) (errno=111)
ajp_send_request::jk_ajp_common.c (1311): (ajp13) error connecting to the backend server (errno=111)
Tying It All Together
Enabling Tomcat on your sites
Enabling Tomcat Support :: CLI
/scripts/addservlets --domain=example.com
http://www.example.com/jsptest.jsp
Removing Tomcat Support
/scripts/remservlets --
domain=example.com
Remotes <Host> container from server.xml
Removes cp_jkmount.conf for provided site
The User End
Deploying Applications
WAR Deployment :: The easy way
unzip filename.war
# unzip example.war
Archive: example.war
creating: META-INF/
inflating: META-INF/MANIFEST.MF
inflating: helloworld.jsp
creating: WEB-INF/
inflating: WEB-INF/web.xml
inflating: index.html
#
How Deployment Works
The appBase is scanned for WAR files every 10 seconds
WAR files are 'exploded' into the site's work directory
/usr/local/jakarta/tomcat/work/Catalina/example.com/war_file_name/
What Happens:
Application is now accessible via:
− http://example.com:8080/appname
mod_jk must be configured to recognize the application now
WAR Deployment :: Configuring mod_jk
Add a JkMount for the application to site include and restart httpd
Example Configuration
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
JkMount /*.do ajp13
JkMount /appname/* ajp13
</IfModule>
Q&A
Resources
Tomcat Project Page
JDK Download Site
Useful Tomcat configuration tips