Apache2 运行正常一段时间,然后停止提供内容,重新启动时出错

2022-01-24 00:00:00 sockets linux debian php apache2
  • 在 Debian 7 Wheezy 上运行的 Apache2
  • 这是一台物理服务器,具有一个 IPv4 地址和多个虚拟主机.
  • Web 应用:Polaric、Redmine、phpMyAdmin 等
  • 此处的 PHP 信息:http://tracking1.sfrkh.net/phpinfo/(将问题解决后删除)
  • Apache2 runing on Debian 7 Wheezy
  • It's a physical server with one IPv4 address and multiple vhosts.
  • Webapps: Polaric, Redmine, phpMyAdmin, etc
  • PHP-info here: http://tracking1.sfrkh.net/phpinfo/ (will be removed when problem is resolved)

当我的服务器启动时,一切正常.Apache2 开始提供内容,我的网站按预期运行.

When my server boots, everything works OK. Apache2 starts serving content, and my websites are working as expected.

一段时间"后(几天到几周),我无法再访问我的任何网站.Apache2 停止向我的浏览器提供内容.

After 'some time' (a few days to a couple of weeks), I can no longer access any of my websites. Apache2 stops serving content to my browser.

这是我几个月来反复出现的问题.我第一次体验它,是在安装和配置所有东西几天后.

This is a recurring problem I've had for a few months. First time I experienced it, was a few days after installing and configuring everything.

如果我重新启动,一切都会恢复正常.一段时间后问题再次出现.

If I reboot, everything is back to normal. The problem appears again after 'some time'.

首先,当我尝试启动或重启 apache2 时:

First, when I try to start or restart apache2:

# apache2ctl start 
- OR -
# /etc/init.d/apache2 start
(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
Action 'start' failed.
The Apache error log may have more information.

然后我用 netstat 检查监听套接字:

Then I check for listening sockets with netstat:

# netstat -ltnp | grep ':80'
tcp  0  0 0.0.0.0:8081    0.0.0.0:*       LISTEN      16100/jsvc.exec
tcp6 0  0 :::80           :::*            LISTEN      14794/apache2

然后我尝试停止 apache2:

Then I try to stop apache2:

# apache2ctl stop
httpd (pid 9124?) not running

- 或 -

# /etc/init.d/apache2 stop
Stopping web server: apache2.

然后我再次运行 netstat 命令,我得到了与上面完全相同的结果.甚至 PID 都没有改变.

Then I run the netstat command again, I got the exact same result as above. Not even the PID changed.

当我从 netstat 杀死 PID 并再次启动 apache2 时:

When I kill the PID from netstat and start apache2 again:

# kill -9 14794
# apache2ctl start

..然后一切恢复正常.

..then everything is back to normal.

一切恢复正常后的Netstat:

Netstat after everything is back to normal:

# netstat -ltnp | grep ':80'
tcp  0  0 0.0.0.0:8081    0.0.0.0:*       LISTEN      16100/jsvc.exec
tcp6 0  0 :::80           :::*            LISTEN      16434/apache2

存在问题时的 Netstat 和一切正常后的 netstat 对我来说似乎没有什么不同.只有 PID 发生了变化.

Netstat while the problem exist, and netstat after everything works, seem no different to me. Only the PID has changed.

一段时间"后问题再次出现.

The problem appears again after 'some time'.

我不知道从这里去哪里.尝试搜索谷歌、这些论坛、其他论坛,但找不到适合我的解决方案.如您所见,我让服务器重新启动并运行,但问题一次又一次地出现.

I don't know where to go from here. Tried searching google, these forums, other forums, but can't find a solution that works for me. As you can see, I get the server back up and running, but the problem appears again and again.

有什么可能导致这种情况的想法吗?

Any ideas of what could be causing this?

我希望我找到了正确的论坛.Google 是我的朋友,关于类似主题的大部分有用建议都来自这个论坛 :)

And I hope I've turned to the right forum. Google is my friend, and most of the useful advice on similar topics, comes from this forum :)

提前感谢您的帮助!

推荐答案

The Apache error log may have more information.

这看起来像是开始的地方.

This looks like the place to start.

看起来这里有两个问题:1)一段时间后 apache 失败,2)发生这种情况时您无法重新启动 Apache.

Looks like there are two problems here: 1) apache fails after a while, and 2) you can't restart Apache when that happens.

首先是问题 2.一种可能性是您有两个 Apache 安装正在运行,一个正在从另一个获取端口.

Problem 2 first. One possibility is that you have two Apache installs running, and one is grabbing the ports off the other.

另外,Apache 正在死机,正在重新启动,但没有正确写入其 PID 文件,因此当您要求它重新启动时,它无法正确杀死自己.

Alternatively, Apache is dying, restarting, but not writing its PID files properly, so when you ask it to restart, it can't kill itself properly.

或者,它可以很好地写入 PID 文件,但是 apache2ctl(或您运行它的用户)没有对它们的读取权限(不太可能).

Alternatively, it's writing the PID files just fine, but apache2ctl (or the user you're running it as) doesn't have read access to them (less likely).

无论哪种方式,PID 文件似乎都是错误的,因为它正在寻找 PID 9124,但 Apache 在 PID 14794 上运行.鉴于无法打开日志",这看起来像是一个权限问题.尝试以对日志和 pidfile 具有读/写访问权限的人身份重新启动 Apache,例如 sudo apachectl graceful,或者以 apache 用户身份进行.

Either way, the PID files seem wrong, given that it's looking for PID 9124, but Apache is running on PID 14794. And given the "unable to open logs", that looks like it's a permissions thing. Try restarting Apache as someone with read/write access to the logs and pidfiles, like sudo apachectl graceful, or doing it as the apache user.

如果可行,那么作为一种解决方法,您可以尝试通过 root 或 apache 的 cron 定期运行 apache2ctl graceful - 但这是一个令人讨厌的、讨厌的混搭.

If that works, then as a workaround, you could try periodically running apache2ctl graceful through root or apache's cron - but that's a nasty, nasty kludge.

更糟糕的是,这样的事情会确保它死了然后重新启动:apache2ctl 优雅 ||(pkill apache2 && apachectl start)

To get even nastier, something like this would make damn sure it died and restarted: apache2ctl graceful || (pkill apache2 && apachectl start)

真正要做的是找出失败的原因 - 问题 1.

The real thing to do though, is find why it's failing - problem 1.

我敢打赌,这又是 PID 文件的权限问题:也就是说,在 httpd.conf 中,您要求它在一定数量的连接后重新启动连接处理程序(MaxRequestsPerChild 设置),但是当他们重新启动时,他们无法写入 pid 文件来更新它们.这可能会导致这种情况.不过,许多其他事情也会如此.

My bet is that it's a permissions problem on the PID files again: that is, say in httpd.conf, you've asked it to restart the connection handlers after a certain number of connections (MaxRequestsPerChild setting), but when they restart they can't write to the pid files to update them. That could cause this. So would lots of other things, though.

不幸的是,调试会检查您的 PID 文件夹和上面所有文件夹的文件权限;运行 apache 的进程 ID 和用户 (ps -ef | grep -Pi "apache|http");pid 文件的内容;您运行 apache2ctl 的用户;您的 httpd.conf 的内容;以及系统日志的内容.

Unfortunately, debugging that would take checking of the file permissions on your PID folders and all folders above that; the process ids and user that apache is running as (ps -ef | grep -Pi "apache|http"); the contents of the pid files; the user you're running apache2ctl as; the contents of your httpd.conf; and the contents of your syslog.

我们可以在这里调试哪些东西,但也许如果您在这些东西中搜索看起来相关的东西,然后发布它们?

Which is more than we could debug here, but maybe if you search through those things for relevant-looking things, and post them?

相关文章