MySQL server gets restarted continually (CentOS 6.5 VPS 1 GB RAM)
Hi everyone,
I have a CentOS 6.5 VPS with 1 GB RAM. Over the last 10 days or so, I noticed that the mysql server had gone down because I got the following error message while trying to log in: Quote:
Code:
131203 7:07:50 [Note] /usr/sbin/mysqld: Normal shutdown Code:
service mysql restart Code:
Starting MySQL. SUCCESS! I talked to a support representative and the only thing he was able to come up with was that the database server seemed to be getting restarted because of insufficient memory: Code:
root@centosvps [~]# free -m However, I noticed that when running a simple query (note that this database has over 6 million records) the CPU usage of mysql went up to 99.7%! but the memory usage did not increase significantly. I appreciate any comments. They will be more than welcome. |
Quote:
This is a completely false statement and a pretty common misconception with Linux. If you look at the above output you see 26 MB of free memory and you're like WTF is going on with my system. But without going into the gory details Linux kernel manages memory differently than Windows and will only "clean" the memory when it is required for use with another application. Until then memory that had been used by the system at one point in time will go into a "dirty inactive" status. Using free -m always provides confusing output. Run a cat /proc/meminfo to see what is actually going on with your memory. Here is one of my prod servers running with a bunch of memory. Running a free -m shows that there is little to no free memory: Code:
free -m Code:
cat /proc/meminfo Reviewing the above output I can see the following: Code:
MemTotal: 20418256 kB This tells me I actually have 12759668 KB free of my 201418256 KB. Another note. You're cached memory which is the second line in the free -m output can give you an idea of how much you actually have free but its not 100% accurate. As you can see in my meminfo file, 15432136 KB of memory are cached but 6396636 KB are still active so only 12651936KB is available to be cleaned for use. Sounds like the support rep honestly didnt know what the problem was and I feel for those folks as I've done that job before working for a hosting company. And at the end of the day most of their scope's of support dont provide troubleshooting services. They will say, oh your MySQL is dying? Well reprovision it and it wont happen again. Basically its the data and config you are doing to the system that will cause it to crash. If you take their out of the box image I'm sure MySQL runs fine and unless you pay them or they provide actual server administration services you won't get very far with support. What does your /var/log/messages file report around the time the service dies? What exists in /var/lib/mysql when the service dies before you restart it? |
You can find plenty of these links on Google but here's one with some more info on the memory management:
http://knowledgelayer.softlayer.com/...ory-management |
@Kustom42:
Thank you SO VERY MUCH for that detailed, in-depth explanation. As to your questions, What does your /var/log/messages file report around the time the service dies? I checked the /var/log/messages file around the time MySQL died and there was nothing about MySQL. What exists in /var/lib/mysql when the service dies before you restart it? I had to recreate the issue by killing mysql and then restarting it again. AFTER KILLING MYSQL: Code:
root@vps-centos [/var/lib/mysql]# ls -l Code:
root@vps-centos [/var/lib/mysql]# ls -l Code:
srwxrwxrwx 1 mysql mysql 0 Dec 3 15:40 mysql.sock= Code:
-rw-rw---- 1 mysql mysql 6 Dec 3 15:40 vps-centos.pid |
Quote:
Now you're starting to do some troubleshooting. So in the Linux world everything exists as a flat file, including processes. The issue here is that the .pid and .sock files are being removed somehow and that causes MySQL to think it has died and stop functioning. Now all you have to do is figure out what is actually causing it to be deleted. The .pid file is what is used by MySQL to establish that a mysql process is running. It uses this as a check to prevent MySQL from starting multiple daemons as well as to store some info about the current running process. The .sock file is for establishing the socket connection to bind an open port.(This is actually done via one of the /proc/pid/fd/* files as each process will have a file in its "fd" directory for each socket used but MySQL uses this additional file as well) I see a .err file which usually indicates there is something being logged. Is there a separate mysql.err log file? What are the contents of your /var/log/mysql/ directory? Also, this being a VPS it is quite possible that you are in fact over utilizing your VPS and the process is being automatically killed by the hypervisor host. 9/10 support folks will have no idea what this means but if you push your way up the food chain you can have them check for an OOM or Out of Memory kill error logged on the VPS hypervsior. A VPS hypervisor with most cloud hosting solutions is a little finicky and 99% have no hard utilization limits set. What that means is that you are sitting on a box with 64GB of memory that you share with a bunch of other folks. You pay for 1GB so they setup alerts and auto OOM(out of memory) kills to kill processes that consume more resources than they are allocated via the soft limits. They can also put hard limits in place but the downside to this is it can render an entire VM unusable until it is rebooted if its the hard limit in some circumstances. Now here are a couple of next troubleshooting steps before getting back on the phone with support for another headache: Install sar if it is not already installed. Run "sar -q" as root to see if is installed. Code:
Setup a file watch for your .pid file. BE CAREFUL with this one, if you forget about it it will fill up your filesystem which should take basically forever but I have no idea how much space you have available. Code:
Again monitor your filesystem closely and kill this if space is an issue although one line of text every few seconds isn't much space. |
Thanks again!
Quote:
Code:
root@vps-centos [/var/log]# ls And thanks again for the tip on the watchdog for the .pid file. I will mark this thread as solved as I received more help than I even expected, and will add to your reputation. Have a nice day! |
Nice post.
|
All times are GMT -5. The time now is 08:30 AM. |