Chinaunix首页 | 论坛 | 博客
  • 博客访问: 293354
  • 博文数量: 155
  • 博客积分: 1688
  • 博客等级: 上尉
  • 技术积分: 1560
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-17 08:06
文章分类
文章存档

2011年(16)

2009年(137)

2008年(2)

分类: LINUX

2009-06-06 03:05:57

centos 安装配置Tomcat
一、下载Tomcat 6 Binary Distributions 文件
     wget
二、解压缩Tomcat部署文件到 /usr/local/tomcat
#tar -zxf apache-tomcat-6.0.14.tar.gz
#mv apache-tomcat-6.0.14 /usr/local/tomcat
三、测试安装(注意环境变量JAVA_HOME必需提前设置)
启动:
#/usr/local/tomcat/bin/startup.sh
关闭:
#/usr/local/tomcat/bin/shutdown.sh
四、部署tomcat服务使自动运行(以jsvc方式)
    1、解压jsvc包(/usr/local/tomcat/bin/下)
       #tar -zxf jsvc.tar.gz
    2、编译jsvc及测试(jdk安装目录:/usr/local/jdk)
       #cd /usr/local/tomcat/bin/jsvc-src
       #chmod +x chmod +x configure
       #./configure --with-java=/usr/local/jdk
       #make
       #cp jsvc ../
       #cp /usr/local/tomcat/bin/jsvc-src/native/Tomcat5.sh /etc/init.d/tomcatd
       编辑成chkconfig可以启动的文件,见备注。
       #vi /etc/init.d/tomcatd
       添加执行用户
       #useradd tomcat
       确保tomcat用户能够读取server.xml文件
       #chmod -R +r /usr/local/tomcat/
       #chmod +x tomcatd
       测试是否能启动
       #./tomcatd start
       #./tomcatd stop
       部署自动运行
       #chkconfig tomcatd on

       #service tomcatd start
       #service tomcatd status
       #service tomcatd stop
==================jsvc方法脚本 /etc/init.d/tomcatd================

#!/bin/sh
#
# Startup Script for Tomcat6
#
# chkconfig: - 88 14
# description: Tomcat Daemon
# processname: jsvc
# pidfile: /var/run/jsvc.pid
# config:
#
# Source function library.
. /etc/rc.d/init.d/functions
#
# Adapt the following lines to your configuration
JAVA_HOME=/usr/local/jdk
CATALINA_HOME=/usr/local/tomcat
DAEMON_HOME=$CATALINA_HOME/bin
TOMCAT_USER=tomcat

# for multi instances adapt those lines.
TMP_DIR=/usr/local/tomcat/temp
PID_FILE=/var/run/jsvc.pid
CATALINA_BASE=/usr/local/tomcat
CATALINA_OPTS=
CLASSPATH=\
$JAVA_HOME/lib/tools.jar:\
$CATALINA_HOME/bin/commons-daemon.jar:\
$CATALINA_HOME/bin/bootstrap.jar

start(){
echo starting tomcat ...
$DAEMON_HOME/jsvc \
-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 '&1' $CATALINA_OPTS \
-cp $CLASSPATH org.apache.catalina.startup.Bootstrap

}

stop(){
echo stopping tomcat ...
$DAEMON_HOME/jsvc \
    -stop \
    -pidfile $PID_FILE \
    org.apache.catalina.startup.Bootstrap
}

status() {
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt
    read line < /tmp/tomcat_process_count.txt
    if [ $line -gt 0 ]; then
      echo -n "tomcatd ( pid "
      ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap" | awk '{printf $1 " "}'
      echo ") is running..."
    else
      echo "Tomcat is stopped"
    fi
}

case "$1" in

     start)
        # Start Tomcat
        start
        exit $?
        ;;
     stop)
        # Stop Tomcat
        stop
        exit $?
        ;;
     restart)
        stop
        sleep 3
        start
        exit $?
        ;;
     status)
        status
        exit $?
        ;;
     *)
       echo "Usage: tomcatd {start|stop|restart|status}"
       exit 1
       ;;
esac

五、部署tomcat服务使自动运行(非jsvc方式)
       #chmod +x tomcatd
       测试是否能启动
       #./tomcatd start
       #./tomcatd stop
       部署自动运行
       #chkconfig tomcatd on

       #service tomcatd start
       #service tomcatd status
       #service tomcatd stop

============================非jsvc方法脚本 /etc/init.d/tomcatd==============================================================
#!/bin/bash
#
# Startup script for Jakarta Tomcat
#
# chkconfig: - 88 14
# description: Jakarta Tomcat Java Servlet/JSP Container


TOMCAT_HOME=/usr/local/tomcat
TOMCAT_STOP=$TOMCAT_HOME/bin/shutdown.sh
TOMCAT_START=$TOMCAT_HOME/bin/startup.sh

#Necessary environment variables
export CATALINA_HOME=$TOMCAT_HOME
export JAVA_HOME=/usr/local/jdk


# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

#Check for tomcat script
if [ ! -f $TOMCAT_HOME/bin/catalina.sh ]
then
    echo $TOMCAT_HOME/bin/catalina.sh
    echo "Tomcat not available..."
    exit
fi

start() {
    echo "Starting Tomcat: "
    #daemon $TOMCAT_START
    $TOMCAT_START
    echo
    touch /var/lock/subsys/tomcatd
# We may need to sleep here so it will be up for apache
#    sleep 5
#Instead should check to see if apache is up by looking for http.pid
}

stop() {
    echo $"Shutting down Tomcat: "
    echo $TOMCAT_STOP
    $TOMCAT_STOP
    rm -f /var/lock/subsys/tomcatd.pid
    #如果不能关闭tomcat时(tomcat有时的bug),调用以下代码#
    pid=`ps -ef|grep "java"|grep "tomcat"|grep -v "grep"|awk '{print $2}'`
    if [ "$pid" = "" ] ; then
       echo "tomcat is shutdown now!"
    else
       echo "force kill tomcat'pid $pid now"
       kill -9 $pid
    fi

}

status() {
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}' | wc | awk '{print $2}' >/tmp/tomcat_process_count.txt
    read line < /tmp/tomcat_process_count.txt
if [ $line -gt 0 ]; then
    echo -n "tomcatd ( pid "
    ps ax --width=1000 | grep "[o]rg.apache.catalina.startup.Bootstrap
start" | awk '{printf $1 " "}'
    echo ") is running..."
else
    echo "Tomcat is stopped"
fi
}

case "$1" in
    start)
        start
        ;;
     stop)
        stop
        ;;
     restart)
        stop
        sleep 3
        start
        ;;
     status)
        status
        ;;
     *)
        echo "Usage: tomcatd {start|stop|restart|status}"
     exit 1
esac


阅读(1085) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~