daemon.sh
文件vim bin/daemon.sh
#!/bin/sh
#chkconfig:2345 10 90
#description:tomcat
JAVA_HOME=/opt/tomcat/jdk1.8.0_401
CATALINA_HOME=/opt/tomcat/apache-tomcat-9.0.37
TOMCAT_USER=root
其中
/opt/tomcat/apache-tomcat-9.0.37
为 Tomcat 的安装目录
cp daemon.sh /etc/init.d/tomcat
chkconfig --add tomcat
chkconfig --list
vim /usr/lib/systemd/system/tomcat.service
[Unit]
Description=Apache Tomcat
Documentation=https://tomcat.apache.org
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=forking
Group=root
User=root
ExecStart=/opt/tomcat/apache-tomcat-9.0.89/bin/startup.sh
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
其中
/opt/tomcat/apache-tomcat-9.0.37
为 Tomcat 的安装目录
systemctl daemon-reload
systemctl enable tomcat.service
附:操作命令
systemctl status tomcat.service
systemctl start tomcat.service
systemctl stop tomcat.service
systemctl reload tomcat.service
systemctl enable tomcat.service
systemctl disable tomcat.service
SET JAVA_HOME=D:\\jdk\\jdk-8u221-windows
SET JRE_HOME=D:\\jdk\\jdk-8u221-windows\\jre
SET CATALINA_HOME=D:\\tomcat\\apache-tomcat-9.0.89
其中
D:\\jdk\\jdk-8u221-windows
为 JDK 安装目录;D:\\tomcat\\apache-tomcat-9.0.89
为 Tomcat 的安装目录
service.bat install tomcat
其中
tomcat
为服务名称
若配置成服务后程序包未加载,可修改 Tomcat 目录权限为完全控制