Linux下添加Tomcat服务并开机启动Tomcat

配置之前:

  安装JDK:

  # rpm -ivh jdk-8u11-linux-x64.rpm

1. 在/etc/init.d/下新建tomcat文件,并输入以下内容:

#!/bin/bash
#
# /etc/rc.d/init.d/tomcat
# init script for tomcat precesses
#
# processname: tomcat
# description: tomcat is a j2se server
# chkconfig: 2345 86 16
# description:  Start up the Tomcat servlet engine.

if [ -f /etc/init.d/functions ]; then
        . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ]; then
        . /etc/rc.d/init.d/functions
else
        echo -e "/atomcat: unable to locate functions lib. Cannot continue."
        exit -1
fi

RETVAL=$?
CATALINA_HOME="/usr/local/tomcat"

case "$1" in
start)
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
            echo $"Starting Tomcat"
            $CATALINA_HOME/bin/startup.sh
        fi
        ;;
stop)
        if [ -f $CATALINA_HOME/bin/shutdown.sh ];
          then
            echo $"Stopping Tomcat"
            $CATALINA_HOME/bin/shutdown.sh
        fi
        ;;
*)
        echo $"Usage: $0 {start|stop}"
        exit 1
        ;;
esac

exit $RETVAL

2. 为tomcat文件提升权限:

# chmod 755 tomcat

3. 设置开机启动:

# chkconfig --add tomcat

4. 如果是编译安装JDK,在tomcat安装目录下的./bin/catalina.sh文件中加入以下变量:

export JAVA_HOME=/YOURPATH
export JRE_HOME=$JAVA_HOME/jre
export CATALINA_HOME=/YOURPATH/tomcat
export CATALINA_BASE=/YOURPATH/tomcat
export CATALINA_TMPDIR=/YOURPATH/tomcat/temp 

5. reboot一下之后,验证setup 及 service tomcat status

 

 End.

posted @ 2013-06-25 09:36  lianche  阅读(2343)  评论(0编辑  收藏  举报