Apache崩溃:无法分配内存

时间:2017-09-02 07:07:25

标签: php apache amazon-web-services memory-management memory-leaks

我遇到了一个反复出现的问题,为什么我的ubuntu服务器在过去两天的同一时间内完全无法使用。在崩溃期间,我甚至无法通过SSH进入它。

Ubuntu服务器位于amazon aws t2.micro实例上,运行在1 gb ram上,Ubuntu 16.04 apache错误日志如下所示

[Wed Aug 30 18:02:23.710072 2017] [autoindex:error] [pid 7505] [client 60.191.38.77:57957] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.cgi,$
[Wed Aug 30 18:02:23.710126 2017] [:error] [pid 7505] [client 60.xx.xx.xx:57957] script '/var/www/html/404.php' not found or unable to stat
[Wed Aug 30 19:11:54.375001 2017] [autoindex:error] [pid 11307] [client 45.55.21.189:52050] AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.html,index.cgi$
[Wed Aug 30 19:11:54.376134 2017] [:error] [pid 11307] [client 45.xx.xx.xx:52050] script '/var/www/html/404.php' not found or unable to stat

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory

mmap() failed: [12] Cannot allocate memory
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[Wed Aug 30 20:50:00.570286 2017] [core:notice] [pid 31139] AH00051: child pid 17670 exit signal Aborted (6), possible coredump in /etc/apache2
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[Wed Aug 30 21:03:27.234926 2017] [core:notice] [pid 31139] AH00051: child pid 18507 exit signal Aborted (6), possible coredump in /etc/apache2
[Wed Aug 30 21:03:27.354905 2017] [core:notice] [pid 31139] AH00051: child pid 18511 exit signal Aborted (6), possible coredump in /etc/apache2
[Wed Aug 30 21:03:27.354927 2017] [core:notice] [pid 31139] AH00051: child pid 18512 exit signal Aborted (6), possible coredump in /etc/apache2
[Wed Aug 30 21:03:42.865027 2017] [core:notice] [pid 31139] AH00051: child pid 18506 exit signal Aborted (6), possible coredump in /etc/apache2
[Wed Aug 30 21:03:46.984235 2017] [core:notice] [pid 31139] AH00051: child pid 18529 exit signal Aborted (6), possible coredump in /etc/apache2
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[crit] Memory allocation failed, aborting process.
[Wed Aug 30 21:14:50.194072 2017] [core:notice] [pid 31139] AH00051: child pid 18605 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Wed Aug 30 21:14:50.482541 2017] [core:notice] [pid 31139] AH00051: child pid 18618 exit signal Aborted (6), possible coredump in /etc/apache2
[Thu Aug 31 07:09:50.271441 2017] [mpm_prefork:notice] [pid 1321] AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Thu Aug 31 07:09:50.274044 2017] [core:notice] [pid 1321] AH00094: Command line: '/usr/sbin/apache2'

此时服务器无法访问 8月30日星期三19:11:54 基于AWS上的日志和流量监控器。

我对Apache在内存和并发连接方面的工作原理知之甚少。我所拥有的网站流量很低。 是否有一些配置文件我可能搞砸了? .BTW memory_limit -1 根据PHP文档没有限制 或者我该怎么做才能找到问题的原因,我正在考虑将服务器文件迁移到AWS beanstalk实例(部署助手加扩展助手,AFAIK)重新开始。

有没有我可以知道可能导致崩溃的脚本。我有太多的脚本加上运行laravel PHP框架+第三方脚本会让你很难勾勒出来哪一个是嫌犯。

我非常感谢一个解释错误log.i.e

的答案
  • 脚本做了这个......

  • Apache似乎已经这样做了......

  • 然后Ubuntu做了这个......

  • 导致了这个......

1 个答案:

答案 0 :(得分:5)

借用@arkascha在评论中所说的,崩溃是由一些使用大量内存且未经过优化的脚本引起的。 以下步骤将帮助其他人面临类似问题。

  1. 将php脚本内存限制限制在合理的范围内 到你跑步的地方。
  2. 有交换文件,非常重要我没有一个导致文件 整个系统在内存密集型处理过程中崩溃。 (在我的 Apache正在使用我1GB的所有可用内存, 字面上导致系统崩溃) (交换文件基本上是硬盘上的文件,用于为从处理器内存传输的程序提供空间。额外的RAM,但速度慢
  3. 找到问题的根源(我还没有找到技术或工具 概述php内存使用,但我认为有一些可用)。另一个 方式也是查找具有长查询(多个连接等)的脚本,这些通常是原因。
  4. 可能很明显,但可能不那么明显,得到一些额外的内存 为您的服务器。您的webapp可能需要比您当前更多 有。
  5. 缓存数据。这样做有很多技巧。基本上它 涉及加载非真正需要动态加载的静态数据。