网上说的有很多, 我只记录一种
1. 切换到 /etc/init.d/ 目录下
2. sudo vim tomcat
3. 在打开的文件里写入以下内容
#!/bin/sh
# chkconfig:
# description: Auto-starts tomcat
# /etc/init.d/tomcat
# Tomcat auto-start
# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network
RETVAL=
export JRE_HOME=/usr/share/jdk1./jre
export CATALINA_HOME=/opt/source/apache-tomcat-8.0.
export CATALINA_BASE=/opt/source/apache-tomcat-8.0.
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
ps -fwwu tomcat | grep apache-tomcat|grep -v grep | grep -v PID | awk '{print $2}'|xargs kill -
echo " OK"-
# [ $RETVAL -eq ] && rm -f /var/lock/...
return $RETVAL
fi
} case "$1" in
start)
start
;;
stop)
stop
;; restart)
echo $"Restaring Tomcat"
$ stop
sleep
$ start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit
;;
esac
exit $RETVAL
4. sudo sysv-rc-conf 打开, 找到 tomcat 一栏, 把如下图所示打叉的地方都勾中, 重启下系统, 再打开 localhost:8080 , 即可生效
附 sudo sysv-rc-conf 命令截图