生活分享

  • 首页
HETAO
业余码农、业余机械爱好者
  1. 首页
  2. 未分类
  3. 正文

小内存服务器MYSQL出现OUT OF MEMORY错误

2014年10月12日 696点热度 0人点赞 0条评论

网站挂掉了。

上网站一看,提示数据库连接错误,重启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:0kB

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

1
2
3
4
5
6
7
8
9
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

1
2
3
4
5
6
7
8
9
10
11
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

1
2
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
Post Views: 740
标签: 暂无
最后更新:2014年10月12日

jinzhao

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

COPYRIGHT © 2022 生活分享. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

浙ICP备14004285号-1