参考:https://www.cnblogs.com/fps2tao/p/8488596.html
1、编写tomcat脚本
在/etc/init.d/目录下创建tomcat服务脚本文件
cd /etc/init.d
nano tomcat
复制粘贴以下内容
#!/bin/bash # # tomcat startup script for the Tomcat server # # # chkconfig: 345 80 20 # description: start the tomcat deamon # # Source function library . /etc/rc.d/init.d/functions prog=tomcat8 JAVA_HOME=/usr/java/jdk1.8.0_202-amd64 # 根据自己的路径改写JAVA_HOME export JAVA_HOME CATALANA_HOME=/usr/local/server/tomcat # 根据自己的路径改写CATALANA_HOME export CATALINA_HOME case "$1" in start) echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;; stop) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh ;; restart) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh sleep 2 echo echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;; *) echo "Usage: $prog {start|stop|restart}" ;; esac exit 0
2、赋权限,测试tomcat脚本
[root@localhost /]# cd /etc/init.d/ [root@localhost init.d]# chmod 755 tomcat8 #赋予权限 [root@localhost init.d]# service tomcat8 start #启动服务 Starting tomcat8 (via systemctl): [ 确定 ] [root@localhost init.d]# service tomcat8 stop #停止服务 Stopping tomcat8 (via systemctl): [ 确定 ] [root@localhost init.d]# service tomcat8 restart #重启服务 Restarting tomcat8 (via systemctl): [ 确定 ]
3、将服务脚本加入到服务启动队列
可用systemctl status tomcat查看服务启动状态
4、重启,测试配置结果