(1)修改脚本文件
[root@localhost bin]# vim /data/apache-tomcat-9.0.56/bin/catalina.sh
添加以下内容(如图)
JAVA_HOME=/usr/jdk1.8.0_202JRE_HOME=$JAVA_HOME/jre
(2)在/usr/lib/systemd/system/中创建tomcat9.service文件
[root@localhost apache-tomcat-9.0.56]# vim /usr/lib/systemd/system/tomcat9.service
粘贴下面的内容到tomcat9.service文件
[Unit]Description=TomcatAfter=syslog.target network.target remote-fs.target nss-lookup.target [Service]Type=oneshotExecStart=/data/apache-tomcat-9.0.56/bin/startup.shExecStop=/data/apache-tomcat-9.0.56/bin/shutdown.shExecReload=/bin/kill -s HUP $MAINPIDRemainAfterExit=yes[Install]WantedBy=multi-user.target
(3)设置开机启动
[root@localhost apache-tomcat-9.0.56]# systemctl enable tomcat9.serviceCreated symlink from /etc/systemd/system/multi-user.target.wants/tomcat9.service to /usr/lib/systemd/system/tomcat9.service.
(4)其他命令
# 启动/停止/重启tomcatsystemctl start/stop/restart tomcat.service # 启动tomcat