Apache崩溃:无法分配内存

Bob*_*ani 4 php apache memory-leaks memory-management amazon-web-services

我遇到了一个反复出现的问题,为什么在过去两天的大约同一时间我的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'
Run Code Online (Sandbox Code Playgroud)

根据AWS上的日志和流量监控器,服务器将在此时间Wed Aug 30 19:11:54左右无法访问 。

我对Apache在内存和并发连接方面的工作方式了解甚少。我进入的网站访问量低。是否有一些配置文件我可能搞砸了?.BTW memory_limit根据PHP文档是-1无限制, 或者我该怎么做才能找到问题的根源,我正在考虑将服务器文件迁移到AWS Beanstalk实例(一个部署助手加上扩展助手,AFAIK)新的开始。

到处都是我可能知道可能导致崩溃的脚本。我有太多脚本,而且在laravel PHP框架上运行,加上第三方脚本,这真的很难勾勒出哪一个是可疑的。

我将不胜感激一个解释错误log.ie的答案

  • 脚本做到了这一点...

  • Apache似乎已经做到了...

  • 然后Ubuntu这样做了...

  • 这导致了...

Bob*_*ani 7

从@arkascha的评论中借用,该崩溃是由于某些脚本占用大量内存且未进行优化而导致的。以下步骤将帮助其他面临类似问题的人。

  1. 根据您的运行情况,将php脚本的内存限制限制为合理的范围。
  2. 有交换文件,非常重要,我没有一个文件导致在内存密集型处理期间整个系统崩溃。(在我的情况下,Apache正在使用我1GB的所有可用内存,这实际上导致系统崩溃)(交换文件基本上是硬盘上的文件,用于为已从处理器的内存中传输的程序提供空间。额外的RAM,但速度较慢
  3. 找到问题的根源(我还没有找到技巧或工具概述php内存使用情况,但我认为有一些可用的方法)。另一种方法是寻找具有较长查询(多个联接等)的脚本,这通常是原因。
  4. 可能很明显,但可能不太明显,请 为服务器获取一些额外的RAM。您的Web应用程序可能需要的数量超出了您当前的需求。
  5. 缓存数据。有很多技术可以做到这一点。基本上,它涉及到在真正不需要动态加载的情况下加载静态数据。