本站文章除注明转载外,均为本站原创或者翻译。
本站文章欢迎各种形式的转载,但请18岁以上的转载者注明文章出处,尊重我的劳动,也尊重你的智商;
本站部分原创和翻译文章提供markdown格式源码,欢迎使用文章源码进行转载;
本文标题:小内存服务器MySQL出现Out of memory错误
2012-12-16更新:这方法貌似没有什么用,MySQL依然一天挂掉3次,给服务器加上swap文件试试。
使用阿里云服务器的第二天,我就收到阿里云的提醒短信,说网站挂掉了。
上网站一看,提示数据库连接错误,重启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
配置进行修改(注意备份):
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<br/>
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
Timeout 45 KeepAlive On MaxKeepAliveRequests 200 KeepAliveTimeout 3 <IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 30 MaxRequestsPerChild 2000 </IfModule>
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