CentOS7-Tomcat开机自启动

问题:每次CentOS重启后,都要手动cd到tomcat的目录下,进行./startup.sh启动tomcat,

解决:

1,修改tomcat的catalina.sh文件

  vim catalina.sh

[ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"

CATALINA_PID="$CATALINA_BASE/tomcat.pid"(这行是你新增加的,在上下两行之间)

# Ensure that any user defined CLASSPATH variables are not used on startup,

修改保存

2,添加或修改tomcat.service

vim /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/local/java/jdk1.8"

PIDFile=/usr/local/tomcat/apache-tomcat-8.5.39/tomcat.pid
ExecStart=/usr/local/tomcat/apache-tomcat-8.5.39/bin/startup.sh
ExecStop=/bin/kill -s QUIT $MAINPID
ExecReload=/bin/kill -s HUP $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

JAVA_HOME和tomcat都是自己的jdk和tomcat的安装路径

修改保存

3,重新载入修改后配置文件,让设置生效。

systemctl daemon-reload

4,启动tomcat.service

systemctl start tomcat.service

5,查看tomcat.service运行状态

systemctl status tomcat.service

6,将tomcat.service添加的自启动

systemctl enable tomcat.service

 

你可能感兴趣的:(CentOS,CentOS7)