如何使用服务 apache2 start 获取更详细的错误消息

如何使用服务 apache2 start 获取更详细的错误消息

我的任务是将 apache 设置从旧的 Linux 系统转移到新系统(Ubuntu 20.04.5 LTS)。将 /etc/apache2 文件夹复制到新服务器并重新启动 apache 后,我遇到了一些问题,这些问题是由配置文件中缺少库引起的。我修复了这些问题,

$ sudo /usr/sbin/apachectl -t
Syntax OK

让我的配置文件确认一下。

但是当我尝试再次启动 apache 时发生了以下情况:

$ sudo service apache2 start
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.

journalctl -xe 没有任何内容,并且 v 为我提供了以下内容:

$ systemctl status apache2.service
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2022-10-13 16:05:54 UTC; 50s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 41669 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)

因此,信息基本上是“你有一个错误,因为你有一个错误”

我怎样才能使 Apache 启动得更详细,以获取可能存在问题的提示?

我已经看过了这里

答案1

systemd 在 20.04 及其他地方提出的建议的问题在于,您不能保证在日志中获取有用的数据。 journalctl -xe包括与 Apache 无关的额外噪音和垃圾,并且systemctl status只会为您提供最后的运行/加载节,这不会为您提供有用的信息。

要真正找出问题所在,您需要使用journalctl不同的选项。运行journalctl -u apache2.service -n 50以从日志中获取最后 50 行。将该数字增加到50您需要获取错误消息所需的行数。

(请注意,在 22.04 及更高版本中,systemd 错误输出指示添加u到参数并指定无法获取特定于服务日志的服务。)


从您的评论中您表明您按照以下说明发现了这些错误:

Oct 13 16:02:43 gl-p-euw4a-pucintra5 apachectl[41648]: no listening sockets available, shutting down
Oct 13 16:02:43 gl-p-euw4a-pucintra5 apachectl[41648]: AH00015: Unable to open logs
Oct 13 16:02:43 gl-p-euw4a-pucintra5 apachectl[41645]: Action 'start' failed.
Oct 13 16:02:43 gl-p-euw4a-pucintra5 apachectl[41645]: The Apache error log may have more information.

您可以在这里单独的讨论线程或简单的 Google 中追踪该错误,但至少您知道现在遇到的错误!

相关内容