httpd.service的任务失败,因为控制进程以错误代码退出。有关详细信息,请参见“systemctl status httpd.service”和“journalctl -xe”。

21

这是由于"/var/www/html"目录不存在导致的。运行命令mkdir "/var/www/html",希望可以解决问题。

我安装了全新的Centos 7系统。然后重启Apache但是Apache无法启动。我已经卡在这个问题上3天了,即使支持团队也无法找出错误。

sudo service httpd start


Failed to start apache :
Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.


httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2016-05-09 16:08:02 BST; 59s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 5710 (code=exited, status=1/FAILURE)

May 09 16:08:02 mike079.startdedicated.de systemd[1]: Starting The Apache HTTP Server...
May 09 16:08:02 mike079.startdedicated.de httpd[5710]: (98)Address already in use: AH00072: make_sock: could not bind to address 85.25.12.20:80
May 09 16:08:02 startdedicated.de httpd[5710]: no listening sockets available, shutting down
May 09 16:08:02 startdedicated.de httpd[5710]: AH00015: Unable to open logs
May 09 16:08:02 startdedicated.de systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
May 09 16:08:02.startdedicated.de kill[5712]: kill: cannot find process ""
May 09 16:08:02 .startdedicated.de systemd[1]: httpd.service: control process exited, code=exited status=1
May 09 16:08:02startdedicated.de systemd[1]: Failed to start The Apache HTTP Server.
May 09 16:08:02 startdedicated.de systemd[1]: Unit httpd.service entered failed state.
May 09 16:08:02 mike: httpd.service failed.

3
你是如何实际修复这个问题的? - hipkiss
12个回答

30

我因为在vhost.conf中犯了一个简单的拼写错误而遇到了相同的错误。 记得要确保配置文件中没有任何错误。

apachectl configtest

建议在获取 PEM 文件类型错误时,在前面使用 "sudo",这可能需要提升提示以查看文件。 - michaelf
1
如果您在另一个用户帐户中运行httpd,而不是简单地添加“sudo”,您可能需要使用“sudo -u [httpd用户]”来检查文件权限。 - jimmymcheung

10

在我的情况下,我之所以出现错误,是因为我已经将文件中的“Listen 80”更改为“listen 443”。

/etc/httpd/conf/httpd.conf 

自从我使用yum命令安装了mod_ssl
yum -y install mod_ssl  

在安装mod_ssl时,文件ssl.conf中存在重复的listen 443指令。

如果您在Linux CentOS(我的Linux)上运行以下命令,就可以验证是否有重复的listen 80listen 443

grep  '443' /etc/httpd/conf.d/*

以下是示例输出。
/etc/httpd/conf.d/ssl.conf:Listen 443 https
/etc/httpd/conf.d/ssl.conf:<VirtualHost _default_:443>
/etc/httpd/conf.d/ssl.conf:#ServerName www.example.com:443

将httd.conf中的监听端口从443改为80即可解决问题。


grep '443' /etc/httpd/conf.d/* 拯救了我的生命。原来有 ssl.conf 文件,而我在 httpd.conf 上设置了虚拟主机。 - Yohanim
挽救了局面。有没有办法查看正确的错误消息?apachectl configtest只验证语法。 - Nisar Ahmed

10

根据您的输出:

没有可用的监听套接字,正在关闭

这基本上意味着,任何一个Apache要监听的端口都已经被另一个应用程序占用了。

netstat -punta | grep LISTEN

将会列出所有正在使用的端口以及需要识别哪个进程是在使用它,这样您就可以killstop或者进行任何您想要的操作了。

在对您的IP进行nmap扫描后,我发现

80/tcp    open     http

所以我猜你解决了它。


谢谢,问题已解决,端口不匹配。 - Didi
在执行了“对你的IP进行nmap扫描”的那一行之后,我有点迷失。你能告诉我接下来应该如何进行测试吗? - John
@John “nmap ip” 是最快的方法。 - sysfiend

7
在命令行中输入journalctl -xe,结果将会显示。
SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket port 83 or 80

这意味着SELinux正在您的机器上运行,您需要将其禁用。然后通过输入以下内容来编辑配置文件:

nano /etc/selinux/config

然后找到这行代码 SELINUX=enforce 并将其改为 SELINUX=disabled

接下来输入以下命令并运行,以启动 httpd:

setenforce 0

最后启动服务器。

systemctl start httpd

4

允许Apache通过防火墙

通过firewalld允许默认的HTTP和HTTPS端口,即端口80和443:

sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp

重新加载防火墙:

sudo firewall-cmd --reload

2

可能有其他服务正在使用端口80:尝试停止其他服务:HTTPD、SSL、NGINX、PHP,使用命令sudo systemctl stop,然后使用命令sudo systemctl start httpd


sudo systemctl stop HTTPD,sudo systemctl stop SSL,sudo systemctl stop NGINX,sudo systemctl stop PHP。 - Astron

1

对我来说,问题如下:

[Sat Sep 10 00:43:20.999998 2022] [auth_digest:error] [pid 123456] (2)No such file or directory: AH01762: Failed to create shared memory segment on file /run/httpd/authdigest_shm.128124
[Sat Sep 10 00:43:20.999999 2022] [auth_digest:error] [pid 123456] (2)No such file or directory: AH01760: failed to initialize shm - all nonce-count checking and one-time noncesdisabled

我刚刚尾随错误日志以获得上述两行内容:

*ADMINSHELL* :/var/opt/custom_path/logs/httpd # tail error_log

问题在于缺少此文件夹:/run/httpd/

解决方案:

mkdir /run/httpd
chown root:httpd /run/httpd
chmod 0710 /run/httpd

完成此操作后,您可以重新启动该服务:

systemctl restart httpd.service

仔细检查:

systemctl status httpd.service

0

我曾经遇到过类似的错误,后来我在位于/etc/httpd/conf.d/vhost.confvhost.conf文件中找到了错误。

如果你正在配置虚拟主机,我建议你查看以下文件,并查找是否有任何错误。

/etc/httpd/conf.d/vhost.conf


0

尝试使用以下命令来查看文件配置中缺失的配置或错误: $ apachectl configtest


0

错误可能出现在任何地方,包括配置、库或二进制文件。控制进程中的错误是系统在无法启动/重新启动服务时抛出的一般性错误。在我的情况下,.service文件中链接到exe的库之一存在问题。修复该库解决了问题。


1
你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心中找到有关如何编写良好答案的更多信息。 - Muhammedogz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接