开发者社区> 问答> 正文

小内存服务器MySQL出现Outofmemory错误


原文地址: http://zengrong.net/post/1762.htm


使用阿里云服务器的第二天,我就收到阿里云的提醒短信,说网站挂掉了。


上网站一看,提示数据库连接错误,重启MySQL了事。


没想到11点钟的时候MySQL再次挂掉了,上服务器一看,原来是MySQL进程被Kill了,原因是 `Out of memory`。



Dec 14 11:38:02 aliyun kernel: [69756.532361] Out of memory: Kill process 11168 (mysqld) score 114 or sacrifice child
Dec 14 11:38:02 aliyun kernel: [69756.532430] Killed process 11168 (mysqld) total-vm:821140kB, anon-rss:57004kB, file-rss:0k




我的服务器内存只有512MB,而且没有配置SWAP分区,看来是MySQL占用的太多内存。找到 `/etc/mysql/my.cnv` 配置进行修改(注意备份):


key_buffer = 16K
max_allowed_packet = 1M
thread_stack = 64K
thread_cache_size = 4
sort_buffer = 64K
net_buffer_length = 2K
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10



同时也修改Apache的配置`/etc/apache2/apache2.conf`


Timeout 45
KeepAlive On
MaxKeepAliveRequests 200
KeepAliveTimeout 3
<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          30
    MaxRequestsPerChild   2000
</IfModule>





重启Apache 和 MySQL


service apache2 restart
service mysql restart



参考资料:


  • http://forum.slicehost.com/index.php?p=/discussion/3629/out-of-memory-kill-process/p1
  • http://www.chrisjohnston.org/tech/configuring-a-lightweight-apache-mysql-install-on-debian-ubuntu

展开
收起
zrong 2012-12-14 17:02:31 12486 0
5 条回答
写回答
取消 提交回答
  • 技术贴。顶起
    2012-12-18 10:25:30
    赞同 展开评论 打赏
  • 我的还没出现过问题哩
    2012-12-17 21:38:41
    赞同 展开评论 打赏
  • Re小内存服务器MySQL出现Outofmemory错误
    设置了之后mysql照样挂,我加上swap file就好了。

    -------------------------

    Re小内存服务器MySQL出现Outofmemory错误
    加上swapfile还是不行,现在MySQL不挂了,Apache挂。
    2012-12-17 21:02:35
    赞同 展开评论 打赏
  •   我的签名 512M的 MYSQL 从来没出过问题
    2012-12-14 20:50:34
    赞同 展开评论 打赏
  • 我的还比较稳定,
    2012-12-14 17:13:17
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
One Box: 解读事务与分析一体化数据库 HybridDB for MySQL 立即下载
One Box:解读事务与分析一体化数据库HybridDB for MySQL 立即下载
如何支撑HTAP场景-HybridDB for MySQL系统架构和技术演进 立即下载

相关镜像