This tutorial will walk you through installing Tomcat 6 on CentOS 5. This installation assumes you have walked through the CentOS - Setup article.
Contents |
First we need to download JDK and JRE 6 for CentOS. Download the following files to your root directory (~) with 'wget'. Note that you may need to change the file names as they may have some URL variables added to the name. Be sure to *not* download the RPM files.
Now that we have the files downloaded we need to create an installation directory for Java.
sudo mkdir /usr/java cd /usr/java
Now we need to execute the installation for Java Development Kit (JDK). In our example we will use specific file names. Keep in mind that your file names may vary.
sudo sh ~/jdk-6u14-ea-bin-b03-linux-amd64-10_mar_2009.bin
Press <space> to advance through the license agreement and type 'yes' to accept. Press <enter> to finish the installation.
Now we need to install the Java Runtime Edition (JRE). In our example we will use specific file names. Keep in mind that your file names may vary.
sudo sh ~/jre-6u14-ea-bin-b03-linux-amd64-10_mar_2009.bin
Press <space> to advance through the license agreement and type 'yes' to accept.
Verify the installation by typing ls. You should see two directories: jdk1.6.0_14 and jre1.6.0_14. Keep in mind that your version numbers may differ slightly.
Next we will need to download and extract Apache Ant. Ant is an installation utility used by several Apache products.
To download Apache Ant you will need to visit the following website to download the installation file: http://ant.apache.org/bindownload.cgi. Scroll down the page and find the .tar.gz under Current Release of Ant. Copy the URL and use wget to download the file to the /usr/share directory. Your version number may differ.
cd /usr/share sudo wget http://mirror.olnevhost.net/pub/apache/ant/binaries/apache-ant-1.7.1-bin.tar.gz
Next we need to unpack that file so we can install it. Note that your version number may be different.
sudo tar -xzf apache-ant-1.7.1-bin.tar.gz
Now we need to download Tomcat 6 to the /usr/share directory. Go to http://tomcat.apache.org/download-60.cgi and download the latest Core version. This will be located under the 'Binary Distributions' portion. Be sure to download the tar.gz package. Note that the version numbers may vary.
cd /usr/share sudo wget http://apache.ziply.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
Now we need to unpack that archive. Note that your version number may be different.
sudo tar -xzf apache-tomcat-6.0.18.tar.gz
We need to create a symbolic link for Ant so other applications can easily find it. Be sure to select the correct version when you create your link.
sudo ln -s /usr/share/apache-ant-1.7.1/bin/ant /usr/bin
We need to setup the JAVA_HOME environment variable so Tomcat can find Java. Be sure to change the directory name according to your version of Tomcat.
cd /usr/share/apache-tomcat-6.0.18/bin sudo vi catalina.sh
This will bring up the vi window. After the first line (that reads #!/bin/sh) you need to add a new line. To insert a new line press the i key to enter insert mode. Enter the following:
JAVA_HOME=/usr/java/jdk1.6.0_14 ** Be sure to adjust the directory name according to your JDK version **
Save the file by pressing the colon (:) key, typing wq, and then pressing <enter>.
Now it is time to test your Tomcat installation. Be sure to note the version number in your path.
cd /usr/share/apache-tomcat-6.0.18/bin sudo ./startup.sh
If it successfully starts you should see something similar to this:
Using CATALINA_BASE: /usr/share/apache-tomcat-6.0.18 Using CATALINA_HOME: /usr/share/apache-tomcat-6.0.18 Using CATALINA_TMPDIR: /usr/share/apache-tomcat-6.0.18/temp Using JRE_HOME: /usr/java/jdk1.6.0_14
If you want to check for errors you can run the following command:
less /usr/share/apache-tomcat-6.0.18/logs/catalina.out
To verify your Tomcat installation is working go to http://12.34.56.78:8080 in your web browser. Be sure to change 12.34.56.78 to your server's IP address.
Right now Tomcat will not start up on it's own so we need to create a startup script for this. To do this:
cd /etc/init.d sudo vi tomcat
Press i to enter insert mode and paste in the following:
#!/bin/bash
# chkconfig: 234 20 80
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
JAVA_HOME=/usr/java/jdk1.6.0_14
export JAVA_HOME
TOMCAT_HOME=/usr/share/apache-tomcat-6.0.18/bin
START_TOMCAT=/usr/share/apache-tomcat-6.0.18/bin/startup.sh
STOP_TOMCAT=/usr/share/apache-tomcat-6.0.18/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."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
Be sure to change the following items in the above file: * JAVA_HOME path * TOMCAT_HOME path * START_TOMCAT path * STOP_TOMCAT path
Once you have those changes made, save the file and quit.
Now we need to change the permissions on the file.
sudo chmod 755 tomcat
We need to set the script to start with other system services and set the runlevels.
sudo /sbin/chkconfig --add tomcat sudo /sbin/chkconfig --level 234 tomcat on
You can verify that it is listed by typing /sbin/chkconfig --list tomcat.
tomcat 0:off 1:off 2:on 3:on 4:on 5:off 6:off
Test your shutdown and startup script.
sudo /sbin/service tomcat stop sudo /sbin/service tomcat start
Tomcat 6 should now be installed under CentOS.
--Kelly Koehn 11:48, 25 March 2009 (CDT)
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

14 Comments
chkconfig is under /sbin
sudo /sbin/chkconfig --add tomcat
sudo /sbin/chkconfig --level 234 tomcat on
Re: chkconfig
needs some info about firewalls
Re: needs some info about firewalls
For Cent 5.9 and lower: sudo iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 8080 -j ACCEPT
For Cent 6: sudo iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
To maintain the change across server restarts, the following command adds an entry to /etc/sysconfig/iptables
sudo /etc/init.d/iptables save
To reverse the above and close the port 8080 again;
Remove the the INPUT..8080 line from /etc/sysconfig/iptables
Run sudo /etc/init.d/iptables save
JDK and JRE links out of date
Re: Links and proxy
Great ....... absolutely to
Good how-to
The current link to the JRE is dead. But it's easily grabbable from the same download page as the SDK. (...growling about Oracle requiring a login to download...)
re: JRE
Download what files?
Download the following files? What files. I see a link to the Oracle download site. I downloaded an HTML.
RE: Download what files?
The links seem to be working correctly. It's not a direct link, but rather a link to download the files that pertain to you. If you can't actually hit the page, try a different browser.
-Rae
Ant not required to install tomcat
re: ant
Thanks much
Please have a better community management.
These articles go a long way in saving lives, seriously!!!
check how http://gluster.helpshiftcrm.com/ is useful
please improve
Add new comment