2010/08/03

Installing Tomcat6 in CentOS 5

Install pre-requisite
1.Download java JDK 6 Update 20 and Java Runtime Environment (JRE) 6 Update 20 bin (NOT RPM)

2.Open terminal, su to root and move downloaded files to /root directory
$ su root
Password:
# mv [.....]
3. Create java environment
# mkdir /usr/java
# cd /usr/java
4. Execute downloaded jdk and jre bins.
# sh /root/jre-6u10-linux-i586.bin

# sh /root/jdk-6u10-linux-i586.bin
5. verify install, and you should see that your /usr/java directory now contains jdk1.6.0_10 and jre1.6.0_10 directories.

Install overview
1. Download and extract Apache Ant (apache-ant-1.7.1-bin.tar.gz) to /usr/share

# cd /usr/share
# tar -xzf apache-ant-1.7.1-bin.tar.gz
2. Download and extract Apache Tomcat (apache-tomcat-6.0.18.tar.gz) to /usr/share
# tar -xzf apache-tomcat-6.0.26.tar.gz
3. Enable ant link
# ln -s /usr/share/apache-ant-1.7.1/bin/ant /usr/bin
4. Set up JAVA_HOME $env in catalina.sh
# cd /usr/share/apache-tomcat-6.0.26/bin
# vi catalina.sh
5. After the first line, add following
JAVA_HOME=/usr/java/jdk1.6.0_20
6. Test config with Tomcat
# cd /usr/share/apache-tomcat-6.0.26/bin
# ./startup.sh
7. Check logs for errors
# less /usr/share/apache-tomcat-6.0.18/logs/catalina.out
8. Fix errors if any. Go to http://localhost:8080 for Tomcat's web interface.

Automate start up
1. Create script in /etc/init.d for automated start up/shutdown

# cd /etc/init.d
# vi tomcat
2.Place following in the file
#!/bin/bash
# chkconfig: 234 20 80
# description: Tomcat Server basic start/shutdown script
# processname: tomcat
JAVA_HOME=/usr/java/jdk1.6.0_20
export JAVA_HOME
TOMCAT_HOME=/usr/share/apache-tomcat-6.0.26/bin
START_TOMCAT=/usr/share/apache-tomcat-6.0.26/bin/startup.sh
STOP_TOMCAT=/usr/share/apache-tomcat-6.0.26/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 o
2. Change permissions
# chmod 755 tomcat
3. Add script to system services
# chkconfig --add tomcat

4. Verify modifications (this script uses levels 2-4)
# chkconfig --level 234 tomcat on
# chkconfig --list tomcat
you should see that service using levels 2, 3 and 4:
tomcat 0:off 1:off 2:on 3:on 4:on 5:off 6:off
5. Test script start up/shutdown
# service tomcat start
# service tomcat stop

0 Comments:

張貼留言