1.在 /etc/init.d目录下面新建一个文本文件,命名为 tomcat ,内容如下:
#!/bin/sh
# chkconfig: 345 99 10
# description: Auto-starts tomcat
# /etc/init.d/tomcatd
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=0
export JAVA_HOME=/home/kafkazookeeperstorm/jdk/jdk1.8.0_171
export JRE_HOME=/home/kafkazookeeperstorm/jdk/jdk1.8.0_171/jre
export CATALINA_HOME=/home/tomcat/tomcat8/apache-tomcat-8.5.34
export CATALINA_BASE=/home/tomcat/tomcat8/apache-tomcat-8.5.34
start()
{
if [ -f $CATALINA_HOME/bin/startup.sh ];
then
echo $"Starting Tomcat"
$CATALINA_HOME/bin/startup.sh
RETVAL=$?
echo " OK"
return $RETVAL
fi
}
stop()
{
if [ -f $CATALINA_HOME/bin/shutdown.sh ];
then
echo $"Stopping Tomcat"
$CATALINA_HOME/bin/shutdown.sh
RETVAL=$?
sleep 1
ps -fwwu root | grep tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -9
echo " OK"
# [ $RETVAL -eq 0 ] && rm -f /var/lock/...
return $RETVAL
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
echo $"Restaring Tomcat"
$0 stop
sleep 1
$0 start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
注意上面内容中红色部分根据实际文件路径修改
2.对刚刚创建的文件 tomcat 修改权限:
chmod 755 tomcat
3.设置tomcat开机启动:
chkconfig tomcat on
4.进行验证,是否设置成功:
a.命令查看:chkconfig --list [name]
b.reboot关机重启后,检查tomcat是否是开机启动。