mysqld service stops once a day on ec2 server

前端 未结 6 418
孤城傲影
孤城傲影 2020-12-12 12:53

Environment Details:

Server: Amazon ec2 Linux
Web Server: Apache
Web Framework: Django with mod_wsgi

Following I have found in the mysql_er

6条回答
  •  有刺的猬
    2020-12-12 13:57

    Like others have mentioned, the problem appears to be your system running low on RAM and MySQL is blowing up due to that. Below is how to go about narrowing down where your system's memory is being used and how to recover from the database going down.

    Take a look at collectd and its plugins. Some of the applicable ones may be the processes plugin and the memory plugin. With those you can see your systems' memory usage and what processes are taking up most of it.

    Depending on how you are running Django, you can configure the worker processes to only process a certain number of requests and then terminate. That way if there is some sort of memory leak in your application it will not persist past that number of requests. For example, if you use Gunicorn, you can use the --max-requests option. Setting it to 500 will drop the worker after it has processed 500 requests.

    The above combined with stats collection will show you some interesting memory usage trends.

    As for the database going down, you can setup process supervision so that if MySQL does die, it will be relaunched automatically. MySQL in latest version of Ubuntu uses Upstart to do just that. If the process dies, Upstart will bring it back up immediately. If you're using another distro that doesn't have this built-in, take a look at Supervisor. While this doesn't fix the problem it will at least mitigate its effects. This should not be seen as the fix but rather a way to keep your application running in case something does go wrong.

提交回复
热议问题