Apache崩溃:无法分配内存

问题描述 投票:3回答:1

我遇到了一个反复出现的问题,为什么我的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'

根据AWS上的日志和流量监视器,服务器将于8月30日星期三19:11:54左右无法访问。

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

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

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

  • 一个脚本做了这个......
  • Apache似乎已经做到了......
  • 然后Ubuntu这样做了......
  • 这导致了......
php apache amazon-web-services memory-management memory-leaks
1个回答
6
投票

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

  1. 根据您运行的内容将php脚本内存限制限制在合理的范围内。
  2. 有交换文件,非常重要我没有一个导致整个系统在内存密集型处理过程中崩溃的文件。 (在我的情况下,Apache使用了我1GB中的所有可用内存,从而导致系统崩溃)(交换文件基本上是硬盘上的一个文件,用于为从处理器内存传输的程序提供空间。额外的RAM,但很慢)
  3. 找到问题的根源(我没有找到一个技术或工具大纲php内存使用,但我认为有一些可用)。另一种方法是查找具有长查询(多个连接等)的脚本,这些通常是原因。
  4. 可能很明显,但可能不那么明显,为您的服务器获取一些额外的RAM。您的webapp可能需要比您现有的更多。
  5. 缓存数据。这样做有很多技巧。基本上它涉及加载静态数据,而不需要动态加载。
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.