当EC2微实例上的ubuntu在内存不足时将其杀死时自动重新启动Mysql

当系统内存不足时,ubuntu 12.04杀死mysql进程:

When the system runs out of memory, ubuntu 12.04 kills the mysql process:

Out of memory: Kill process 17074 (mysqld) score 146 or sacrifice child

所以这个进程最终被杀死了.这发生在服务器负载的高峰期,主要是因为 apache 变得疯狂并吃掉剩余的可用内存.可能的方法是:

So the process ends up killed. This happens at peaks of server load and mainly because of apache getting wild and eating the remaining available memory. Possible approaches could be:

  • 以某种方式更改 mysql 的优先级,这样它就不会被杀死(可能是一个糟糕的修复,因为其他东西会被杀死)
  • 监控mysql的状态并在它被杀死时自动重启(我正在考虑,但不知道如何去做).

你怎么看?

推荐答案

数据库服务器的突然终止是非常严重的崩溃.您需要在生产系统中避免这种情况,因为它可能无法干净地重新启动.

Abrupt termination of a database server is a very serious crash. You need to avoid this in a production system, because it may not restart cleanly.

数据库服务器是一种共享资源,在生产中几乎不应该以计划外的方式终止.唯一应该导致意外终止的是灾难性硬件或电源故障.大多数正确配置的生产数据库服务器每十年或更少地有一次计划外终止.认真的.

The database server is a shared resource, and should almost never terminate in an unplanned fashion in production. The only thing that should cause unplanned termination is a catastrophic hardware or power failure. Most properly configured production data base servers have an unplanned termination once every ten years or less frequently. Seriously.

怎么办?

修复您的 apache 配置.限制它可以使用的工作线程和进程的数量,这样它就不会疯狂运行.了解如何执行此操作.这是至关重要的.请参阅此处:http://httpd.apache.org/docs/current/mod/mpm_common.html#maxrequestworkers

Fix your apache configuration. Limit the number of worker threads and processes it can use, so it can't run wild. Learn how to do this. It's vital. See here: http://httpd.apache.org/docs/current/mod/mpm_common.html#maxrequestworkers

修复您的网络应用程序中导致您的 apache 疯狂运行的缺陷.

Fix the defects in your web app that are causing your apache to run wild.

如果可以,把你的mysqld服务器从apache移到不同的服务器机器上,这样两者就不会争夺相同的硬件资源.

If you can, move your mysqld server to a different server machine from apache, so the two don't contend for the same hardware resources.

配置您的 mysqld 以限制它将接受来自 apache 工作线程或其他客户端的连接数.您的 Web 应用程序可能会处理工作线程需要等待连接的情况.看这里.http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_connections

Configure your mysqld to limit the number of connections it will accept from apache worker threads or other clients. Your web app probably handles the situation where a worker thread needs to wait for a connection. See here. http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_connections

您使用的是 EC2 微型实例吗?你需要做一些认真的调整.请参阅此处:http://ubuntuforums.org/showthread.php?t=1979049

Are you on an EC2 micro instance? You need to do some serious tuning. See here: http://ubuntuforums.org/showthread.php?t=1979049

相关文章