Linux Amazon EC2 - Apache 服务器重启问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9557503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:59:49  来源:igfitidea点击:

Amazon EC2 - Apache server restart issue

linuxapacheamazon-ec2

提问by Mohd Shahid

When i run this command

当我运行此命令时

sudo /etc/init.d/httpd restart

须藤 /etc/init.d/httpd 重启

it gives below error

它给出了以下错误

Stopping httpd: [FAILED]

停止 httpd:[失败]

Starting httpd: (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 no listening sockets available, shutting down Unable to open logs [FAILED]

启动 httpd: (98)Address already in use: make_sock: could not bind to address [::]:80 (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 没有可用的监听套接字,正在关闭down 无法打开日志 [失败]



i checked running programs at port 80 by using

我通过使用检查了端口 80 上正在运行的程序

netstat -lnp | grep :80 (it gives below output)

netstat -lnp | grep :80(它给出以下输出)

tcp 0 0 :::80 :::* LISTEN 21739/httpd

tcp 0 0 :::80 :::* 听 21739/httpd



why i am not able to stop stop apache by using sudo /etc/init.d/httpd restart?

为什么我无法通过使用 sudo /etc/init.d/httpd restart 来停止 apache?

below commands work without issue

下面的命令可以正常工作

sudo apachectl stop

须藤 apachectl 停止

sudo apachectl start

须藤 apachectl 开始

i am using linux micro instance of amazon ec2

我正在使用亚马逊 ec2 的 linux 微型实例

回答by Jeevan Dongre

I feel its better to kill the process itself, find out the process id and kill it and then do a fresh start, it should work fine

我觉得最好杀死进程本身,找出进程ID并杀死它然后重新开始,它应该可以正常工作

回答by littleforest

I ran into this problem when I installed apache from source, but then tried to run

当我从源代码安装 apache 时遇到了这个问题,但随后尝试运行

$ sudo /etc/init.d/httpd restart 

which was using a pre-installed version of apache. The stop directive in /etc/init.d/httpd was not removing the httpd.pid file that was created when starting the source-installed version of apache.

这是使用预装版本的 apache。/etc/init.d/httpd 中的 stop 指令没有删除在启动源安装版本的 apache 时创建的 httpd.pid 文件。

To determine if this is also the reason for your problem, find where the httpd.pid file is getting set when you run

要确定这是否也是您的问题的原因,请查找运行时设置 httpd.pid 文件的位置

$ sudo apachectl start

If you installed from source and apache2 is living in /usr/local/apache2, then the httpd.pid file should get created in /usr/local/apache2/logs. When you stop apache by running

如果您从源代码安装并且 apache2 位于 /usr/local/apache2,则应该在 /usr/local/apache2/logs 中创建 httpd.pid 文件。当您通过运行停止 apache 时

$ sudo apachectl stop

this file should get removed. So to test if the httpd.pid file is causing your problem, start apache by calling

这个文件应该被删除。因此,要测试 httpd.pid 文件是否导致您的问题,请通过调用启动 apache

$ sudo apachectl start

and locate the httpd.pid file. Then try stopping apache by using

并找到 httpd.pid 文件。然后尝试使用停止 apache

$ sudo /etc/init.d/httpd stop

If the original httpd.pid file is still present, then that is why apache is unable to start when you use

如果原来的httpd.pid文件还在,那就是你使用apache无法启动的原因

$ sudo /etc/init.d/httpd start

To get my /etc/init.d/httpd file to work correctly, I explicitly put the call to apachectl in the start and stop methods:

为了让我的 /etc/init.d/httpd 文件正常工作,我在 start 和 stop 方法中明确地调用了 apachectl:

#!/bin/bash
# /etc/init.d/httpd
#
# Path to the apachectl script, server binary, and short-form for messages. 
apachectl=/usr/local/apache2/bin/apachectl 
httpd=/usr/local/apache2/bin/httpd 
pid=/usr/local/apache2/logs/httpd.pid 
prog=httpd 
RETVAL=0

start() {
    echo -n $"Starting $prog: "
    $apachectl -k start
    RETVAL=$?
    echo
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    $apachectl -k stop
    RETVAL=$?
    echo
}

回答by pigfly

I tried this and it works:

我试过这个,它有效:

  1. sudo fuser -k -n tcp 80
  2. sudo service httpd start
  1. 须藤热熔器 -k -n tcp 80
  2. 须藤服务 httpd 启动

Hope this will help you!

希望能帮到你!

Cheers

干杯

回答by Quadrivium

I have had this issue very rarely over the last couple years with a server I've been managing. Unfortunately, if you are getting FAILED after trying to restart, the process that's managing the connection on port 80 won't release it's hold on that port.

在过去的几年里,我一直在管理的服务器上很少遇到这个问题。不幸的是,如果您在尝试重新启动后失败,则管理端口 80 上的连接的进程不会释放它对该端口的保持。

I would try a full "sudo /etc/init.d/httpd stop" wait for that to finish or fail.

我会尝试一个完整的“sudo /etc/init.d/httpd stop”等待它完成或失败。

If that doesn't fix it you'll have to restart the server completely. Hopefully, it's configured to start everything up automatically on restart, but that isn't guaranteed.

如果这不能解决它,您将不得不完全重新启动服务器。希望它被配置为在重新启动时自动启动一切,但这并不能保证。

"apachectl" is also great tool for Apache, but it may not be on this server, it depends on the install and linux distro used.

“apachectl”也是 Apache 的好工具,但它可能不在此服务器上,这取决于安装和使用的 linux 发行版。

If after rebooting the server, apache still fails to start, something bad has happened. I'd consider pulling all the website and conf files for creating a new server at that point, but the apache start, and then failed message output should give you some idea of where to look in the Logs about why it cannot start.

如果重新启动服务器后,apache 仍然无法启动,则发生了一些不好的事情。我会考虑在那时拉出所有网站和 conf 文件以创建新服务器,但是 apache 启动,然后失败的消息输出应该让您了解在日志中查看为什么无法启动的原因。