aws amazon linux ami 上的服务 httpd 重启失败

aws amazon linux ami 上的服务 httpd 重启失败

感谢您的帮助。我最近做了以下事情:

  1. sudo yum update在运行 Amazon Linux ami 的 EC2 实例上运行
  2. 然后,我为子域的 vhost.conf 添加了虚拟主机。
  3. 虽然服务器仍然可以访问,但当我运行时,sudo httpd restart我收到以下信息:

Stopping httpd:                                            [FAILED]
Starting httpd: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/vhost.conf:1
(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
AH00015: Unable to open logs
                                                           [FAILED]

另外,如果我在没有 sudo 的情况下运行重启命令,service httpd restart我会收到以下消息:

rm: cannot remove `/var/run/httpd/httpd.pid': Permission deniedLED]

rm: cannot remove `/var/run/httpd/httpd.pid': Permission denied
Starting httpd: AH00548: NameVirtualHost has no effect and will be removed in the next release /etc/httpd/conf.d/vhost.conf:1
(13)Permission denied: AH00058: Error retrieving pid file /var/run/httpd/httpd.pid
AH00059: Remove it before continuing if it is corrupted.
                                                           [FAILED]

答案1

从您提供的信息来看,似乎有另一个进程正在使用端口 80

尝试执行以下操作:

首先,您需要以 root 用户身份执行它们,要么在命令前添加 sudo,要么在执行任何操作之前,像这样切换到 root 用户:

su -root

并输入 root 密码。

然后,继续:

netstat -tulpn| grep :80

上述命令显示使用端口 80 的连接列表

然后执行以下命令,终止使用 80 端口的进程

kill -9 <process id>

将进程 ID 替换为上一个命令中屏幕上显示的进程号。

然后执行此命令启动httpd进程:

service httpd start
如果上述方法对你不起作用,那么试试这个

试试这个我刚刚测试过:

for i in `lsof -i :80 | grep http | awk {' print $2'}`; do kill -9 $i; done

然后执行重启:

service httpd restart

答案2

查看用户:

id

检查权限:

ls -l /var/run/httpd/httpd.pid

运行它得到<process id>

netstat -tulpn| grep :80

要检查谁运行了 httpd:

ps -ef|grep <process id> 

答案3

因此,关于另一个进程使用端口 80 或 443 或其他端口的答案可能或多或少是正确的,但这看起来像是一个典型的错误,我想分享一下。您永远不应该 kill -9pidof httpd或以其他方式突然终止 apache。如果这样做,您将收到该错误,直到系统终止所有剩余的往返于端口 80 的 tcp 连接。尝试 netstat -alpn | grep ':80' 并检查是否有一堆连接处于 TCP_TIME_WAIT 或类似状态。您必须关闭 apache 服务器,直到这些全部消失。

显然,您也可能遇到这样的问题:在同一台机器上运行 nginx 或 lighttpd,从而阻塞端口,但我敢打赌有人杀死了 apache。所有这些连接消失大约需要两分钟。

相关内容