centos配置tomcat开机自启动


开始本文章之前,请注意各位配置好jdk和tomcat 两者均已配好环境变量,可正常使用。

1 执行指令vi /etc/rc.d/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/tomcat7" #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 添加权限chmod 755 /etc/rc.d/init.d/tomcat,使得脚本文件可执行
3 运行:chkconfig –add /etc/rc.d/init.d/tomcat #将其加到服务中
4 在vim /usr/local/tomcat7/bin/catalina.sh文件中加入以下语句:

export JAVA_HOME=/usr/java/jdk1.7.0_67
export CATALINA_HOME=/usr/local/tomcat7
export CATALINA_BASE=/usr/local/tomcat7
export CATALINA_TMPDIR=/usr/local/tomcat7/temp

启动tomcat服务: service tomcat start
停止tomcat服务: service tomcat stop

你可能感兴趣的:(tomcat,运维)