Installing Tomcat6 on Centos 5.2
Step by step instructions on how to install Tomcat 6 on Centos 5.2.
I did a fresh installation of Centos 5.2 in Xen, following by
yum update
reboot
Next, download JDK from java.sun.com (current jdk-6u7-linux-x64-rpm.bin) and install.
chmod o+x jdk-6u7-linux-x64-rpm.bin
./jdk-6u7-linux-x64-rpm.bin
Edit /etc/profile and add to the nearly end of file
export JAVA_HOME=/usr/java/default
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
and run
. /etc/profile
to export new settings.
Installing Tomcat 6
cd /tmp
wget http://ftp.sh.cvut.cz/MIRRORS/apache/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
tar xvzf apache-tomcat-6.0.18.tar.gz
mv -f apache-tomcat-6.0.18 /opt/tomcat6
Next, create user tomcat and set permissions of /opt/tomcat6
useradd -d /opt/tomcat6 -s /sbin/nologin tomcat
chown -R tomcat /opt/tomcat6
Next, create init script, edit /etc/init.d/tomcat6 and fill it with:
#!/bin/sh # # Startup script for jakarta tomcat # # chkconfig: - 85 20 # description: Tomcat running # processname: tomcat # pidfile: /var/run/tomcat.pid # config:# Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0# Set Tomcat environment. export JAVA_HOME=/usr/java/default export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar export CATALINA_HOME=/opt/tomcat6 export CATALINA_OPTS="-Dbuild.compiler.emacs=true" export PATH=$JAVA_HOME/bin:$PATH [ -f /opt/tomcat6/bin/startup.sh ] || exit 0 [ -f /opt/tomcat6/bin/shutdown.sh ] || exit 0 export PATH=$PATH:/usr/bin:/usr/lib/bin # See how we were called. case "$1" in start) # Start daemon. echo -n "Starting Tomcat: " /opt/tomcat6/bin/startup.sh RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat ;; stop) # Stop daemons. echo -n "Shutting down Tomcat: " /opt/tomcat6/bin/shutdown.sh RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/tomcat ;; restart) $0 stop $0 start ;; condrestart) [ -e /var/lock/subsys/tomcat6 ] && $0 restart ;; status) status tomcat ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 esac exit 0
Set executable flag and ensure it starts on machine boot
chmod +x /etc/init.d/tomcat6
chkconfig tomcat6 on
edit /opt/tomcat6/conf/tomcat-users.xml and modify line
<user username="tomcat" password="tomcat" roles="manager,admin"/>
Now, you should be able to start tomcat and access http://server_ip:8080/
/etc/init.d/tomcat6 start
zainal13. February 2009 at 10:28
This article not helpful. Some of the configuration is not working.
mates13. February 2009 at 23:54Author
What exactly didn’t work for you? This will install basic Tomcat, nothing more.
steve1. March 2009 at 04:46
I think maybe zainal had trouble copying the init.d script text. I used gedit to replace all of the open-close style double quotes with standard double quotes. Other than that everything worked fine. Thanks.
mniedero2. March 2009 at 14:23
The quotation marks in script /etc/init.d/tomcat6 makes troubles. This is the solely problem I could find in your description.
mniedero2. March 2009 at 16:50
There are further problems:
o) quotation marks: Because of this copy/paste from your description above does not work
o) There is neither catalina.pid nor tomcat.pid in /var/run folder
to avoid this, you should add this line into your tomcat6 script:
CATALINA_PID=/var/run/tomcat.pid
In addition, CATALINA_PID must be removed in stop and condrestart case
o) I also had troubles with the case statements so I modified the whole script
according /etc/init.d/postfix (I use postfix instead of sendmail…). This means
that I wrote functions for start() and stop().
Now it works as expected and also service configuration app shows the PID when
tomcat6 is running.
mniedero2. March 2009 at 16:54
This is my /etc/init.d/tomcat6 script:
#!/bin/sh
#
# Startup script for jakarta tomcat
#
# chkconfig: – 85 20
# description: Tomcat running
# processname: tomcat
# pidfile: /var/run/tomcat.pid
# config:
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
# Set Tomcat environment.
JAVA_HOME=/opt/sun/java/jdk1.6.0_12
CATALINA_HOME=/srv/asf/tomcat6
CATALINA_OPTS=”-Dbuild.compiler.emacs=true”
CATALINA_PID=/var/run/tomcat.pid
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CATALINA_HOME/lib/servlet-api.jar
[ -f $CATALINA_HOME/bin/startup.sh ] || exit 0
[ -f $CATALINA_HOME/bin/shutdown.sh ] || exit 0
PATH=$JAVA_HOME/bin:$CATALINA_HOME/bin:$PATH:/usr/bin:/usr/lib/bin
export PATH CLASSPATH JAVA_HOME CATALINA_HOME CATALINA_PID
RETVAL=0
progname=”tomcat”
start() {
# Start daemon.
echo -n $”Starting Tomcat: ”
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/tomcat
echo
return $RETVAL
}
stop() {
# Stop daemons.
echo -n $”Shutting down Tomcat: ”
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/tomcat && rm -f $CATALINA_PID
echo
return $RETVAL
}
restart() {
# restart
stop
start
}
# See how we were called.
case “$1″ in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status tomcat
;;
condrestart)
[ -e /var/lock/subsys/tomcat ] && [ -e $CATALINA_PID ] && restart
;;
*)
echo $”Usage: $0 {start|stop|restart|status|condrestart}”
exit 1
esac
exit $?
mniedero2. March 2009 at 16:55
BTW, the quotation marks now changed, so the script can not be copied using copy/paste!
sachin13. July 2009 at 11:18
toooo gooood