Jakarta Tomcat
From OptionC
| Table of contents |
Introduction
The purpose of this document is to explain how to install Apache Tomcat in a Debian VM. Apache Tomcat is the servlet container portion of the Apache Jakarta Project (http://jakarta.apache.com/tomcat). Note: There is nothing in this document that makes it Xen-specific, so it can be used directly on a physical machine.
Base Installation
Start with a base system, such as the one detailed here. You will need to have a larger amount of diskspace -- a minimum of 512MB, ideally 1GB.
We install Apache 2 on the machine. In addition, we will need APXS so we install apache-dev.
# apt-get update # apt-get install apache2 apache-dev
Installing Java
Download the Java JDK (I used jdk-1_5_0_04-linux-i586.bin).
Uncompress the file and move the result to /usr/local. For simplicity, we'll create a symlink. Finally we set the JAVA_HOME environment variable.
# mv jdk1.5.0_04 /usr/local # ln -s /usr/local/jdk1.5.0_04 /usr/local/java # export JAVA_HOME=/usr/local/java
Installing Tomcat
Download the Jakarta Tomcat binaries. I used version 5.5.9 (which was the latest version as of the beginning of July, 2005). Uncompress/untar the downloaded file and move the resulting directory to /usr/local.
# tar -zxvf jakarta-tomcat-5.5.9.tar.gz # mv jakarta-tomcat-5.5.9 /usr/local
Start Tomcat (this requires the JAVA_HOME environment variable mentioned in the previous section):
# cd /usr/local/jakarta-tomcat-5.5.9/bin # ./startup.sh
Check the log to see if things are running:
# cd ../logs # less catalina.out
Connecting Tomcat and Apache
We need to make Tomcat talk to Apache. This is simple using the Debian packages:
# apt-get install libapache2-mod-jk2 # /etc/init.d/apache2 force-reload
Finally, test. Point a browser to:
http://webserver:8080 (where "webserver" is the name of your webserver)
Tomcat Manager
To allow a user access to the Tomcat Manager we need to edit the /usr/local/jakarta-tomcat-5.5.9/conf/tomcat-users.xml file.
Add the role of manager:
<role rolename="manager"/>
Add the user:
<user username="blah" password="blahblah" roles="manager"/>
Note: The user roles can be a comma-delimited list.
Restart Tomcat (in /usr/local/jakarta-tomcat-5.5.9/bin):
# ./shutdown.sh # ./startup.sh
Now you should be able to log on to the Tomcat Manager at
http://webserver:8080/manager/html
Tomcat Administrator
At one time the Tomcat Administrator module came as part of the Tomcat package. No more. You need to download and install it. I used version 5.5.9 (again) of the administrator.
# tar -zxvf jakarta-tomcat-5.5.9-admin.tar.gz
Merge the administrator files into the directories already created in /usr/local/jakarta-tomcat-5.5.9.
Add a user with appropriate permissions. Add the role of admin:
<role rolename="admin"/>
Add (or update) the user:
<user username="blah" password="blahblah" roles="manager,admin"/>
Restart Tomcat (in /usr/local/jakarta-tomcat-5.5.9/bin):
# ./shutdown.sh # ./startup.sh
Now you should be able to log on to the Tomcat Manager at
http://webserver:8080/admin/
Auto Startup
To have Tomcat auto start/stop at boot/shutdown, create the script /etc/init.d/tomcat with the following contents:
#!/bin/sh -e
#
# tomcat This init.d script is used to start tomcat
# It just calls $TOMCAT_HOME/bin/startup.sh or shutdown.sh
export JAVA_HOME=/usr/local/java
export CATALINA_HOME=/usr/local/jakarta-tomcat-5.5.9
TOMCAT_HOME=/usr/local/jakarta-tomcat-5.5.9
tomcat_stop() {
$TOMCAT_HOME/bin/shutdown.sh
}
tomcat_start() {
$TOMCAT_HOME/bin/startup.sh
}
case $1 in
start)
echo -n "Starting Tomcat server:"
tomcat_start
echo "."
;;
stop)
echo -n "Stopping Tomcat server:"
tomcat_stop
echo "."
;;
reload)
echo -n "Reloading Tomcat server config..."
tomcat_stop
tomcat_start
echo "done."
;;
restart | force-reload)
echo -n "Forcing reload of Tomcat server:"
tomcat_stop
tomcat_start
echo "."
;;
*)
echo "Usage: /etc/init.d/tomcat start|stop|restart|reload|force-reload"
;;
esac
After creating the file, we need to make it executable and ensure the links are set in the /etc/rc#.d directories:
# chmod +x /etc/init.d/tomcat # ln -s /etc/init.d/tomcat /etc/rc0.d/K91tomcat # ln -s /etc/init.d/tomcat /etc/rc1.d/K91tomcat # ln -s /etc/init.d/tomcat /etc/rc2.d/S91tomcat # ln -s /etc/init.d/tomcat /etc/rc3.d/S91tomcat # ln -s /etc/init.d/tomcat /etc/rc4.d/S91tomcat # ln -s /etc/init.d/tomcat /etc/rc5.d/S91tomcat # ln -s /etc/init.d/tomcat /etc/rc6.d/K91tomcat
Adding a MySQL Data Source
To be completed...

