Tomcat  安装
一。所需软件
jdk-1_5_0_*-linux-i586.bin
apache-tomcat-5.5.*.tar.gz
二。JAVA环境的安装
#mkdir /usr/java
#cd /usr/java
#bash jdk-1_5_0_*-linux-i586.bin
这样java sdk将安装到系统/usr/java/jdk1.5.0_*中
三。Tomcat的安装
#tar -zxvf apache-tomcat-5.5.*.tar.gz -C /home
将apache-tomcat-5.5目录改名为tomcat5.5目录,这样 tomcat 将安装到系统/home/tomcat5.5, 然后执行如下命令产生tomcat用户和jsvc程序.
# useradd -s /sbin/nologin -d /home/tomcat5.5 tomcat
# cd /home/tomcat5.5/bin
# tar -zxvf jsvc.tar.gz
# cd jsvc-src
configure  之前需要设置JAVA 环境变量
# ./configure ; make
# cp jsvc ../
四。配置Tomcat的启动
在/etc/init.d目录下重建脚本tomcat5.5( 如果在同一台服务器上跑多个tomcat请保证启动脚本名有所区别)
#/bin/bash
#
#       /etc/rc.d/init.d/tomcat
#
# Starts the tomcat daemon
# Write By  Kevin Zou 2005/02/25
#
# chkconfig: 345 87 13
# description: Tomcat is a JAVA World Wide Web server.  It is used to serve \
#              JSP files .
# processname: tomcat or clutomcat


. /etc/init.d/functions


#Set default LANG
#LANG="zh_CN.UTF-8"
#LANGUAGE="zh_CN.UTF-8:zh_CN.GB2312:zh_CN.GB18030:zh_CN.GBK:zh_CN:zh"
#SUPPORTED="zh_CN.UTF-8:zh_CN.GB2312:zh_CN.GB18030:zh_CN.GBK:zh_CN:zh:en_US.UTF-8:en_US:en"

#export LANG LANGUAGE SUPPORTED

# Set Source name and path
TOMCAT_NAME="tomcat5.5"
TOMCAT_SOURCE="/home/$TOMCAT_NAME"
WEBROOT_NAME="WebRoot"
WEBROOT_SOURCE="/home/$WEBROOT_NAME"

# Set TOMCAT_USER
TOMCAT_USER="tomcat"

# Set default PATH
CATLAIR="/dev/shm/$TOMCAT_NAME"
WEBROOT="/dev/shm/$WEBROOT_NAME"
#UPTOMCAT="$CATLAIR/bin/startup.sh"
#DOWNTOMCAT="$CATLAIR/bin/shutdown.sh"
JSVC="$CATLAIR/bin/jsvc"
JAVA_HOME="/usr/java/jdk1.5.0_06"
CLASSPATH="$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CATLAIR/bin/commons-daemon.jar:$CATLAIR/bin/bootstrap.jar"
CATALINA_BASE="$CATLAIR"
CATALINA_HOME="$CATLAIR"
TMP_DIR="$CATLAIR/temp"
PID_FILE=/var/run/jsvc.pid

PATH="$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH"

DISPLAY="127.0.0.1:1.0"

# Set root open files
#ulimit -n 65535

# If user is tomcat or anther user , you mast vi /etc/security/limits.conf file .
# And you mast add
# tomcat soft nofile 65535
# tomcat hard nofile 65535


#Have 10 or fewer concurrent users
#CATALINA_OPTS="-server -Xms512m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=64m -XX:MaxPermSize=128m -Xss128k -XX:-UseTLAB -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -Djava.awt.headless=true"
CATALINA_OPTS=" -Xms512m -Xmx512m -XX:NewSize=64m -XX:MaxNewSize=64m -XX:MaxPermSize=128m -Xss128k -XX:-UseTLAB -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -Djava.awt.headless=true"

#Have more than 10 concurrent users
#CATALINA_OPTS="-server -Xms1280m -Xmx1280m -XX:NewSize=160m -XX:MaxNewSize=160m -XX:MaxPermSize=128m -Xss128k -XX:-UseTLAB -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -Djava.awt.headless=true"

export DISPLAY CATALINA_OPTS USERNAME BASH_ENV PATH JAVA_HOME CLASSPATH CATALINA_BASE CATALINA_HOME JAVAHOME

UPTOMCAT="$JSVC -jvm server -user $TOMCAT_USER -home $JAVA_HOME -Dcatalina.home=$CATALINA_HOME  -Dcatalina.base=$CATALINA_BASE -Djava.io.tmpdir=$TMP_DIR  -wait 10  -pidfile $PID_FILE -outfile $CATALINA_HOME/logs/catalina.out -errfile $CATALINA_HOME/logs/catalina.out  $CATALINA_OPTS -cp $CLASSPATH org.apache.catalina.startup.Bootstrap"

DOWNTOMCAT="$JSVC -stop -pidfile $PID_FILE  org.apache.catalina.startup.Bootstrap"



prog=$(basename $0)
  

RETVAL=0


#
# See how we were called.
#

flush_webroot() {
    echo -n $"Test WEBROOT_SOURCE and WEBROOT directory "
    [ -d $WEBROOT_SOURCE ] && [ -d $WEBROOT ] && success || failure
    RETVAL=$?
        echo
        [ $RETVAL = 1 ] && exit 0
    echo -n $"Flush WEBROOT file "
     /usr/bin/rsync -zrtopgv $WEBROOT_SOURCE/ $WEBROOT 2>&1 1>/dev/null && success || failure
    RETVAL=$?
        echo
        [ $RETVAL = 1 ] && exit 0

}

mk_temp_tomcat() {
    echo -n $"Copy Tomcat directory to /dev/shm :"
        /bin/cp -a $TOMCAT_SOURCE /dev/shm && success || failure
        RETVAL=$?
        echo
        [ $RETVAL = 1 ] && exit 0
}


rm_temp_tomcat() {
        echo -n $"Delete Tomcat directory from /dev/shm :"
        rm -rf /dev/shm/$TOMCAT_NAME  && success || failure
        RETVAL=$?
        echo
        [ $RETVAL = 1 ] && exit 0
}

mk_temp_webroot() {
    echo -n $"Copy WebRoot directory to /dev/shm :"
    /bin/cp -a $WEBROOT_SOURCE /dev/shm && success || failure
    RETVAL=$?
    echo
    [ $RETVAL = 1 ] && exit 0
}

rm_temp_webroot() {
    echo -n $"Delete WebRoot directory from /dev/shm :"
        rm -rf /dev/shm/$WEBROOT_NAME  && success || failure
        RETVAL=$?
        echo
        [ $RETVAL = 1 ] && exit 0
}


start() {
        echo  -n $"Starting $prog: "
#        [ -d $CATLAIR ] && cd $CATLAIR ; $UPTOMCAT 2>/dev/null && success || failure
        $UPTOMCAT  && success || failure
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}

stop() {
        echo  -n $"Stopping $prog: "
#        [ -d $CATLAIR ] && cd $CATLAIR ;  $DOWNTOMCAT 2>/dev/null && success || failure
    $DOWNTOMCAT && success || failure
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
}

restart() {
        stop
        echo $"Normal startup will continue in 3 seconds."
        sleep 3
    [ -d $WEBROOT ] && rm -rf $WEBROOT
        [ -d $CATLAIR ] && rm -rf $CATLAIR
        mk_temp_webroot
        mk_temp_tomcat
        start
}


case "$1" in
    start)
        [ -d $WEBROOT ] && rm -rf $WEBROOT
        [ -d $CATLAIR ] && rm -rf $CATLAIR
        mk_temp_webroot
        mk_temp_tomcat
            start
            ;;
    stop)
        stop
        rm_temp_webroot
        rm_temp_tomcat
            ;;
    restart)
            restart
            ;;
        status)
                status java   
            ;;
    recopy)
        stop
        rm_temp_webroot
        mk_temp_webroot
        [ ! -d $CATLAIR ] && mk_temp_tomcat
        start
        ;;
    flush)
                flush_webroot
        ;;
    *)
            echo $"Usage: $0 {start|stop|status|restart|recopy|flush}"
            exit 1
esac


exit $RETVAL

以上为tomcat5.5启动脚本, 请仔细阅读并确切的知道其含义,然后编辑存盘后执行以下操作
# chmod 755 /etc/init.d/tomcat5.5
# chckconfig --add tomcat5.5
# service tomcat5.5 start
五。测试方法
#links http://127.0.0.1:8080 查看是否有tomcat的测试页