Apache2可以正常运行一会儿,然后停止提供内容,重新启动时出错 [英] Apache2 runs fine for a while, then stops serving content, error when restarting

查看:46
本文介绍了Apache2可以正常运行一会儿,然后停止提供内容,重新启动时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • Apache2在Debian 7 Wheezy上运行
  • 这是一台具有一个IPv4地址和多个虚拟主机的物理服务器.
  • Web应用程序:Polaric,Redmine,phpMyAdmin等
  • 此处的PHP-info: 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'.

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

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的读/写访问权限的人员(例如 sudo apachectl graceful )或以apache用户身份进行操作来重新启动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启动)

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?

这篇关于Apache2可以正常运行一会儿,然后停止提供内容,重新启动时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆