Installing Apache Tomcat

Status
Not open for further replies.

onlineteachers.co.nr

Right off the assembly line
dear you have noy mentioned the operating system.
is it linux or windows??

for linux

I am explaining it for redhat linux.

make sure you have 1.5 version of sun's JDK.check /usr/java/<jdk_version>/


get the core package of tomcat from apache wensite.
make directory /user/local/tomcat
this makes upgrade easier later.

[guru@onlineteachers ~]$ tar -xzf apache-tomcat-5.5.17.tar.gz
[guru@onlineteachers ~]$ sudo mv apache-tomcat-5.5.17 /usr/local/
[guru@onlineteachers ~]$ cd /usr/local/
[guru@onlineteachers local]$ sudo ln -s apache-tomcat-5.5.17/ tomcat

sudu is used where commands need to be run as root.

now set environment variables

JAVA_HOME - needs to point to your Java install. (If you used the latest Sun RPM that will be /usr/java/jdk1.5.0_6)
CATALINA_HOME - should be set to /usr/local/tomcat

start Tomcat with the command /usr/local/tomcat/bin/startup.sh and stop Tomcat with the command /usr/local/tomcat/bin/shutdown.sh

Setting Tomcat up as a Service

To do this you need to copy the code below and save it as a file called tomcat in the folder /etc/init.d:
# This is the init script for starting up the
# Jakarta Tomcat server
#
# chkconfig: 345 91 10
# description: Starts and stops the Tomcat daemon.
#

# Source function library.
. /etc/rc.d/init.d/functions

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

tomcat=/usr/local/tomcat
startup=$tomcat/bin/startup.sh
shutdown=$tomcat/bin/shutdown.sh
export JAVA_HOME=/usr/java/jdk1.5.0_06
export CATALINA_HOME=/usr/local/tomcat

start(){
echo -n $"Starting Tomcat service: "
$startup
RETVAL=$?
echo
}

stop(){
action $"Stopping Tomcat service: " $shutdown
RETVAL=$?
echo
}

status(){
numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l`
if [ $numproc -gt 0 ]; then
echo "Tomcat is running..."
else
echo "Tomcat is stopped..."
fi
}

restart(){
stop
sleep 5
start
}


# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 1
esac

exit 0

You may have to change the value for JAVA_HOME if your JDK is in a different location to mine. You then need to make the file executable with the command:
sudo chmod +x /etc/init.d/tomcat

And finally you need to set it to start at boot with the command:
sudo chkconfig --add tomcat

You now have a working Tomcat install that will start it self at boot time. You can also interact with it using the service command to start, stop, restart and see the status of the service at any time. E.g.
sudo service tomcat start
sudo service tomcat satus
sudo service tomcat stop
 
Last edited:
Status
Not open for further replies.
Top Bottom