环境:
Amazon EC2 Instance - m1.medium Ubuntu 12.04 Apache 2.2.22 - Running a Drupal Site Using MySQL DB Server RAM info: ~$ free -gt total used free shared buffers cached Mem: 3 1 2 0 0 0 -/+ buffers/cache: 0 2 Swap: 0 0 0 Total: 3 1 2 Hard drive info: Filesystem Size Used Avail Use% Mounted on /dev/xvda1 7.9G 4.7G 2.9G 62% / udev 1.9G 8.0K 1.9G 1% /dev tmpfs 751M 180K 750M 1% /run none 5.0M 0 5.0M 0% /run/lock none 1.9G 0 1.9G 0% /run/shm /dev/xvdb 394G 199M 374G 1% /mnt
问题
大约两天前,该网站开始失败,因为MySQL服务器被Apacheclosures,并显示以下消息:
kernel: [2963685.664359] [31716] 106 31716 226946 22748 0 0 0 mysqld kernel: [2963685.664730] Out of memory: Kill process 31716 (mysqld) score 23 or sacrifice child kernel: [2963685.664764] Killed process 31716 (mysqld) total-vm:907784kB, anon-rss:90992kB, file-rss:0kB kernel: [2963686.153608] init: mysql main process (31716) killed by KILL signal kernel: [2963686.169294] init: mysql main process ended, respawning
这表明虚拟机占用了0.9GB,但是我的RAM有2GB的空闲空间,所以1GB仍然是免费的。 我明白,在Linux应用程序可以分配更多的内存比物理可用。 我不知道这是否是问题,这是它第一次发生。 显然,MySQL服务器试图重新启动,但显然没有内存,它不会重新启动。 这是它的错误日志:
Plugin 'FEDERATED' is disabled. The InnoDB memory heap is disabled Mutexes and rw_locks use GCC atomic builtins Compressed tables use zlib 1.2.3.4 Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12 Completed initialization of buffer pool Fatal error: cannot allocate memory for the buffer pool Plugin 'InnoDB' init function returned error. Plugin 'InnoDB' registration as a STORAGE ENGINE failed. Unknown/unsupported storage engine: InnoDB [ERROR] Aborting [Note] /usr/sbin/mysqld: Shutdown complete
我只是重新启动了Mysql服务。 大约两个小时后又发生了。 我重新启动它。 然后9小时后再次发生。 那么我想到了apache.conf的MaxClients参数,所以我去检查了一下。 它被定为150.我决定把它降到60。
<IfModule mpm_prefork_module> ... MaxClients 60 </IfModule> <IfModule mpm_worker_module> ... MaxClients 60 </IfModule> <IfModule mpm_event_module> ... MaxClients 60 </IfModule>
一旦我这样做了,我重新启动了apache2服务,并且一天中的3/4顺利进行。 由于晚上MySQL服务再次closures,但是这次它并没有被Apache2服务中止。 相反,它将以下消息称为OOM-Killer:
kernel: [3104680.005312] mysqld invoked oom-killer: gfp_mask=0x201da, order=0, oom_adj=0, oom_score_adj=0 kernel: [3104680.005351] [<ffffffff81119795>] oom_kill_process+0x85/0xb0 kernel: [3104680.548860] init: mysql main process (30821) killed by KILL signal
现在我没有想法了。 有些文章指出,理想的做法是用下面的内容来改变内核的行为(把它包含到文件/etc/sysctl.conf中)
vm.overcommit_memory = 2 vm.overcommit_ratio = 80
所以不会发生过度使用。 我想知道这是否是要走的路? 请记住,我不是服务器pipe理员,我有基本的知识。
预先感谢一堆。