Tomcat已在centos中安装好,并且已配置好jdk的环境变量,但是Tomcat一直启动不起来。之前按照部署文档用的chkconfig进行Tomcat自启动配置,但是配置失败。现按照以下方法进行配置,配置成功。
1.配置tomcat8开机启动
在/usr/lib/systemd/system目录下增加tomcat8.service文件,命令如下:
vi /usr/lib/systemd/system/tomcat8.service
把以下内容拷贝进tomcat8.service文件内:
[Unit]
Description=Tomcat-8
After=syslog.target network.target remote-fs.target nss-lookup.target[Service]
Type=oneshot
ExecStart=/work/gw-app/apache-tomcat-8.5.88-scanapi/bin/startup.sh
ExecStop=/work/gw-app/apache-tomcat-8.5.88-scanapi/bin/shutdown.sh
ExecReload=/bin/kill -s HUP $MAINPID
RemainAfterExit=yes[Install]
WantedBy=multi-user.target
确保修改ExecStart、ExecStop等路径为你的实际路径。
2.允许tomcat8开机启动
执行以下命令:
systemctl enable tomcat8
3.tomcat8常见命令
systemctl enable tomcat8.service //开机自启tomcat
systemctl disable tomcat8.service //禁用开机自启tomcat
systemctl start tomcat8.service //启动tomcat
systemctl stop tomcat8.service //关闭tomcat
systemctl restart tomcat8.service //重启tomcat
systemctl status tomcat8.service //查看状态tomcat
参考文章:Centos中安装tomcat并设置开机自启