网站挂掉了。
上网站一看,提示数据库连接错误,重启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
|
参考资料: