1) 进入你tomcat安装目录
cd /opt/server/apache-tomcat-8.0.18/bin
2) 复制脚本到服务中
cp catalina.sh /etc/init.d/tomcat
3) 修改/etc/init.d/tomcat
vim /etc/init.d/tomcat
#!/bin/sh
#------------------------------------------------------------
# 添加以下三个配置
#chkconfig:2345 10 90
#description: Tomcat8 Daemon
#processname:Tomcat8
#---------------------------------------------------------------
#Set Tomcat Var
# Tomcat 目录
export CATALINA_HOME=/opt/server/apache-tomcat-8.0.18
# Java 安装目录
export JAVA_HOME=/usr/share/jdk1.7.0_79
#########################################################################
tomcat停止是没有提示的我们可以在文件中添加以下配置:
假设你现在还在编辑文件
按ESC输入”/stop“找到判断参数为stop的位置:
elif [ "$1" = "stop" ] ; then
shift
SLEEP=5
if [ ! -z "$1" ]; then
echo $1 | grep "[^0-9]" >/dev/null 2>&1
if [ $? -gt 0 ]; then
SLEEP=$1
shift
fi
fi
FORCE=0
if [ "$1" = "-force" ]; then
shift
FORCE=1
fi
if [ ! -z "$CATALINA_PID" ]; then
if [ -f "$CATALINA_PID" ]; then
if [ -s "$CATALINA_PID" ]; then
kill -0 `cat "$CATALINA_PID"` >/dev/null 2>&1
if [ $? -gt 0 ]; then
echo "PID file found but no matching process was found. Stop aborted." exit 1
fi
else
echo "PID file is empty and has been ignored."
fi
else
echo "\$CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted."
exit 1
fi
fi
eval "\"$_RUNJAVA\"" $LOGGING_MANAGER $JAVA_OPTS \
-Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" stop
#加入以下三行代码
if [ $? == 0 ]; then
echo "Tomcat Stoped."
fi
4) 配置服务
chkconfig --add tomcat #这里的tomcat是在第二步中脚本文件名
chkconfig --list #查看服务是否配置成功