centos 7 tomcat 8 开机自启

在 /usr/lib/systemd/system 创建文件 tomcat.service,内容如下:

[Unit]
Description=Tomcat
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking

Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64"

PIDFile=/root/boguan/apache-tomcat-8.5.47/tomcat.pid
ExecStart=/root/boguan/apache-tomcat-8.5.47/bin/startup.sh
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

修改 /root/boguan/apache-tomcat-8.5.47/bin/setclasspath.sh,在开头处加入

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64/jre

然后执行

systemctl daemon-reload

systemctl enable tomcat.service

systemctl start tomcat.service

如果启动了,但没有成功,可以使用以下命令显示详细信息
systemctl status tomcat.service

 

posted on 2022-05-17 15:36  空明流光  阅读(45)  评论(0编辑  收藏  举报

导航