在开机启动目录建立相关项。
cd /etc/init.d
vi /etc/init.d/tomcat
以tomcat安装目录/usr/local/tomcat/为例,填入代码如下:
#!/bin/sh#chkconfig: 2345 10 90# description: Starts and Stops the Tomcat daemon.###############################################Startup script for Tomcat on Linux#filename tomcat.sh#Make sure the java and the tomcat installation path has been added to the PATHJAVA_HOME=/usr/java/jdk1.8.0_77CATALINA_HOME=/usr/local/tomcatexport JAVA_HOMEexport CATALINA_HOME###############################################start_tomcat=/usr/local/tomcat/bin/startup.shstop_tomcat=/usr/local/tomcat/bin/shutdown.shstart() {echo -n "Starting tomcat: "${start_tomcat}echo "tomcat start ok."}stop() {echo -n "Shutting down tomcat: "${stop_tomcat}echo "tomcat stop ok."}# See how we were calledcase "$1" instart)start;;stop)stop;;restart)stopsleep 10start;;*)echo "Usage: $0 {start|stop|restart}"esacexit 0
其中:JAVA_HOME=/usr/java/jdk1.8.0_77 中的jdk版本请根据自己系统所安装版本,位置调整,方法为:
ls /usr/java/
给脚本权限:
chmod 755 tomcat
添加到服务:
chkconfig --add tomcat
开机启动项:
chkconfig --level 345 tomcat on
好了,现在可以通过 service tomcat start 命令启动 Tomcat 了,关闭及重启服务的命令也类似,只是将 start 换成 stop 或 restart。
附件下载地址 https://www.cnop.net/uploadfile/2016/0805/20160805022735452.zip