I have a centos 6 server running apache2, php and MySQL. The apache config has a few virtual sites as the server runs six websites, three of the six sites use MySQL and the other three do not.
Recently I have found that the sites using MySQL crash - report error "unable to connect to sql database.."
After looking in the logs, it looks like there are multiple instances of apache running which eat up all my memory - this causes the server to kill the MySQL process in order to stop the server from dieing, and moments later it will restore (on occasions I have to repair some tables)
In order to try and control the situation I have dropped my max_connections down to 100 - however this has not helped
Right now im not sure if I need more memory (1GB installed) or if I being DoS attacked. In all honesty we do expect high volumes of traffic to the server but how can I know if a single IP is continuously hitting the box?
I have pasted some output during "normal operation" below if it helps
free -m
total used free shared buffers cached
Mem: 992 771 221 0 15 87
-/+ buffers/cache: 668 323
Swap: 976 39 937
ps aux | grep apache
apache 17148 0.1 3.4 430836 35036 ? S 06:34 0:10 /usr/sbin/httpd
apache 17150 0.1 3.3 430592 34560 ? S 06:34 0:12 /usr/sbin/httpd
apache 17157 0.1 3.3 333192 33896 ? S 06:34 0:13 /usr/sbin/httpd
apache 17164 0.1 3.3 333712 33984 ? S 06:34 0:09 /usr/sbin/httpd
apache 17167 0.1 3.4 430576 34584 ? S 06:34 0:12 /usr/sbin/httpd
apache 17168 0.1 3.3 430064 34312 ? S 06:34 0:11 /usr/sbin/httpd
apache 17176 0.1 3.3 430564 34560 ? S 06:34 0:11 /usr/sbin/httpd
apache 17184 0.1 3.4 432124 35500 ? S 06:34 0:08 /usr/sbin/httpd
apache 17186 0.1 3.3 430088 34384 ? S 06:34 0:14 /usr/sbin/httpd
apache 17188 0.1 3.3 333464 34028 ? S 06:34 0:13 /usr/sbin/httpd
apache 17190 0.1 3.4 430548 34616 ? S 06:34 0:08 /usr/sbin/httpd
apache 17193 0.1 3.3 333372 33548 ? S 06:34 0:12 /usr/sbin/httpd
apache 17195 0.1 3.4 333716 34672 ? S 06:34 0:11 /usr/sbin/httpd
apache 17225 0.1 3.3 430044 33584 ? S 06:35 0:10 /usr/sbin/httpd
apache 17239 0.1 3.4 430568 34796 ? S 06:35 0:11 /usr/sbin/httpd
apache 17241 0.1 3.3 430480 34284 ? S 06:35 0:11 /usr/sbin/httpd
apache 17290 0.1 3.4 430948 34824 ? S 06:35 0:10 /usr/sbin/httpd
apache 21095 0.1 3.1 331300 32344 ? S 08:15 0:01 /usr/sbin/httpd
apache 30858 0.1 3.2 430148 33304 ? S Aug04 0:49 /usr/sbin/httpd
apache 31996 0.1 3.2 430168 33480 ? S Aug04 0:48 /usr/sbin/httpd
oom
orKilled
. I suspect you are running out of memory and MySQL is being killed. It would also be worth runningmysqltuner.pl
to evaluate MySQL's memory requirements. Adding a resource graphing tool like Cacti, Munin, Zabbix, Observium, etc. would be a good idea too.