I recently setup Apache Tomcat 6.0.10 and in this post I will share the steps that I went through to install it on my RedHat Linux AS 4 server.
mkdir /usr/local/tomcat/
mv apache-tomcat-6.0.10.tar.gz /usr/local/tomcat/
cd /usr/local/tomcat
tar -zxvf apache-tomcat-6.0.10.tar.gz
rm apache-tomcat-6.0.10.tar.gz
Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
Since my JDK is installed in the directory /usr/java/default, I have the following set in my /etc/profile file to always set the JAVA_HOME variable and to put the Java binaries into my PATH:
JAVA_HOME=/usr/java/default; export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH; export PATH
cd /usr/local/tomcat/apache-tomcat-6.0.10/bin ./startup.sh
Your output should look like:
Using CATALINA_BASE: /usr/local/tomcat/apache-tomcat-6.0.10 Using CATALINA_HOME: /usr/local/tomcat/apache-tomcat-6.0.10 Using CATALINA_TMPDIR: /usr/local/tomcat/apache-tomcat-6.0.10/temp Using JRE_HOME: /usr/java/default
And doing a ps -aef | grep tomcat should show a Tomcat process running.
http://192.168.1.50:8080
And like magic, the default Tomcat page showed up in my web browser. The IP address or hostname will most likely be different than the one I specified above.
./shutdown.sh
cd /usr/local/tomcat ln -sf apache-tomcat-6.0.10 current
I use these symbolic links in the startup and shutdown scripts that I reference below.
In order to start Tomcat automatically when my server boots up, I setup a script in /etc/init.d. Follow the instructions below to do the same.
vi /etc/init.d/tomcat
…and place the following script in it:
#!/bin/bash # # Startup script for Tomcat # # chkconfig: - 86 15 # description: Tomcat is a JSP server. # processname: tomcat JAVA_HOME=/usr/java/default export JAVA_HOME tomcat_home=/usr/local/tomcat/current/bin start_tomcat=/usr/local/tomcat/current/bin/startup.sh stop_tomcat=/usr/local/tomcat/current/bin/shutdown.sh start() { echo -n "Starting tomcat: " cd $tomcat_home ${start_tomcat} echo "done." } stop() { echo -n "Shutting down tomcat: " cd $tomcat_home ${stop_tomcat} echo "done." } # See how we were called case "$1" in start) start ;; stop) stop ;; restart) stop sleep 10 start ;; *) echo "Usage: $0 {start|stop|restart}" esac exit 0
chmod 755 /etc/init.d/tomcat
chkconfig --add tomcat
chkconfig --level 35 tomcat on
chkconfig --list tomcat
And your output should look like the following:
tomcat 0:off 1:off 2:off 3:on 4:off 5:on 6:off
/etc/init.d/tomcat start /etc/init.d/tomcat stop
Furthermore, you should be able to reboot your system and ensure Tomcat starts automatically.