I recently had a Debian server where MySQL was crashing every few days. After some hunting through the logs, it turned out oom-killer was killing the MySQL process because the system had run out of memory.
It wasn’t MySQL that was using the memory though, it was actually Apache2.
After some hunting around I found a few sites that look at how to resolve the issue.
This one primarily just suggests rebooting after figuring out what is causing it. This is fair enough, but doesn’t solve the root cause.
This site suggested limiting the amount of memory the kernel can allocate so that it can’t over allocate, resulting in crashes. I think this is a great idea but I’d rather not play with kernel settings if I don’t have to.
What I have done at this point is as this site suggested. I have reduced the amount of server processes that Apache2 is allowed to run. So far this seems to have done the trick. Where I was having 2-3 crashes a week we’ve now gone 2 weeks without a crash so hopefully this has resolved the problem.
So to summarise, what I did was open /etc/apache2/apache2.conf and changed the default
<IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 0 </IfModule>
<IfModule mpm_prefork_module> StartServers 2 MinSpareServers 2 MaxSpareServers 5 MaxClients 40 MaxRequestsPerChild 0 </IfModule>