一、将startup.sh和shutdown.sh新建软连接到/usr/bin
ln -s /usr/local/apache-tomcat-8.5.38/bin/startup.sh /usr/bin/startup.sh
ln -s /usr/local/apache-tomcat-8.5.38/bin/shutdown.sh /usr/bin/shutdown.sh
二、新建/etc/init.d/tomcat文件
#!/bin/bash #chkconfig:345 80 90 start(){ echo -n "Starting Tomcat service:" startup.sh echo "tomcat is succeessfully started up" } stop(){ echo -n "Shutting down tomcat: " shutdown.sh echo "tomcat is succeessfully shut down." } status(){ numproc=`ps -ef | grep catalina | grep -v "grep catalina" | wc -l` if [ $numproc -gt 0 ]; then echo "Tomcat is running..." else echo "Tomcat is stopped..." fi } restart(){ stop start } case "$1" in start) start ;; stop) stop ;; status) status ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart}" exit 1 esac
三、注册服务
chkconfig --add tomcat
四、查看服务
chkconfig --list|grep tomcat
五、启动服务
service tomcat start