![在 Ubuntu 16.04 上安装 tomcat 后无法启动:“tomcat.service 的作业失败,因为控制进程以错误代码退出。”](https://linux22.com/image/1061800/%E5%9C%A8%20Ubuntu%2016.04%20%E4%B8%8A%E5%AE%89%E8%A3%85%20tomcat%20%E5%90%8E%E6%97%A0%E6%B3%95%E5%90%AF%E5%8A%A8%EF%BC%9A%E2%80%9Ctomcat.service%20%E7%9A%84%E4%BD%9C%E4%B8%9A%E5%A4%B1%E8%B4%A5%EF%BC%8C%E5%9B%A0%E4%B8%BA%E6%8E%A7%E5%88%B6%E8%BF%9B%E7%A8%8B%E4%BB%A5%E9%94%99%E8%AF%AF%E4%BB%A3%E7%A0%81%E9%80%80%E5%87%BA%E3%80%82%E2%80%9D.png)
我按照步骤操作https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04安装tomcat 8.5.24在 Ubuntu 16.04 上,直到sudo ufw allow 8080
在“第 6 步:调整防火墙并测试 Tomcat 服务器”运行。
然后我就无法启动 tomcat,
$ sudo systemctl start tomcat
Job for tomcat.service failed because the control process exited with error code. See "systemctl status tomcat.service" and "journalctl -xe" for details.
并且该链接http://localhost:8080/
在 Firefox 和 Google Chrome 浏览器上均不起作用。
我想知道如何解决这个问题。
以下是我按照上面的输出信息进行的操作sudo systemctl start tomcat
。看起来/opt/tomcat/bin/startup.sh
成功了,但/opt/tomcat/bin/shutdown.sh
失败了。非常感谢您的帮助!
$ systemctl status tomcat.service
● tomcat.service - Apache Tomcat Web Application Container
Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Fri 2017-12-01 18:55:30 EST; 2s ago
Process: 19490 ExecStop=/opt/tomcat/bin/shutdown.sh (code=exited, status=1/FAILURE)
Process: 19478 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
Main PID: 19440 (code=exited, status=127)
Dec 01 18:55:30 ocean systemd[1]: tomcat.service: Control process exited, code=exited status=1
Dec 01 18:55:30 ocean systemd[1]: Failed to start Apache Tomcat Web Application Container.
Dec 01 18:55:30 ocean systemd[1]: tomcat.service: Unit entered failed state.
Dec 01 18:55:30 ocean systemd[1]: tomcat.service: Failed with result 'exit-code'.
$ journalctl -xe
-- Unit tomcat.service has begun starting up.
Dec 01 18:51:24 ocean startup.sh[18873]: Existing PID file found during start.
Dec 01 18:51:24 ocean startup.sh[18873]: Removing/clearing stale PID file.
Dec 01 18:51:24 ocean startup.sh[18873]: Tomcat started.
Dec 01 18:51:24 ocean shutdown.sh[18885]: PID file found but no matching process was found. Stop aborted.
Dec 01 18:51:24 ocean systemd[1]: tomcat.service: Control process exited, code=exited status=1
Dec 01 18:51:24 ocean systemd[1]: Failed to start Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has failed.
--
-- The result is failed.
Dec 01 18:51:24 ocean systemd[1]: tomcat.service: Unit entered failed state.
Dec 01 18:51:24 ocean systemd[1]: tomcat.service: Failed with result 'exit-code'.
Dec 01 18:51:34 ocean systemd[1]: tomcat.service: Service hold-off time over, scheduling restart.
Dec 01 18:51:34 ocean systemd[1]: Stopped Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has finished shutting down.
Dec 01 18:51:34 ocean systemd[1]: Starting Apache Tomcat Web Application Container...
-- Subject: Unit tomcat.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has begun starting up.
Dec 01 18:51:35 ocean startup.sh[18896]: Existing PID file found during start.
Dec 01 18:51:35 ocean startup.sh[18896]: Removing/clearing stale PID file.
Dec 01 18:51:35 ocean startup.sh[18896]: Tomcat started.
Dec 01 18:51:35 ocean shutdown.sh[18908]: PID file found but no matching process was found. Stop aborted.
Dec 01 18:51:35 ocean systemd[1]: tomcat.service: Control process exited, code=exited status=1
Dec 01 18:51:35 ocean systemd[1]: Failed to start Apache Tomcat Web Application Container.
-- Subject: Unit tomcat.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit tomcat.service has failed.
--
-- The result is failed.
Dec 01 18:51:35 ocean systemd[1]: tomcat.service: Unit entered failed state.
Dec 01 18:51:35 ocean systemd[1]: tomcat.service: Failed with result 'exit-code'.
我的 Java 版本是
$ java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
$ javac --version
javac 9.0.1
更新:
如果sudo systemctl start tomcat
我运行
cd /opt/tomcat/bin
sudo ./catalina.sh run
http://本地主机:8080/显示正确的网页。那么,为什么一个不起作用而另一个起作用呢?
答案1
我也遇到过这种情况。有帮助的是删除此文件:/opt/tomcat/temp/tomcat.pid
这是 tomcat 在启动时创建的临时文件。显然,如果出于某种原因该文件存在,服务将无法启动。–
答案2
对我来说已经正常运行
sudo sh -c 'chmod +x /opt/tomcat/latest/bin/*.sh'
我参加了这个教程
https://linuxize.com/post/how-to-install-tomcat-8-5-on-ubuntu-18-04/