令人发狂的间歇性 Wordpress:建立数据库连接时出错 [英] Maddening Intermittent Wordpress: Error establishing database connection

查看:53
本文介绍了令人发狂的间歇性 Wordpress:建立数据库连接时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的 Wordpress 网站每天都停止响应,页面开始返回可怕的建立数据库连接时出错".MySQL 日志中没有任何内容,我对可能导致问题的原因一无所知.我们没有很多站点访问者,并且机器是中型 EC2 实例.有人对如何解决此问题有任何想法吗?

Every day or so our Wordpress sites stop responding, the pages begin returning the dreaded 'Error establishing database connection'. There is nothing in the MySQL logs, and I'm at a loss as to what could be causing the issue. We don't have a lot of site visitors, and the machine is a Medium EC2 instance. Anyone have any ideas on how to resolve this?

推荐答案

我遇到了类似的问题,即 MySQL 间歇性崩溃.原来是Apache配置.机器人对站点进行暴力破解并最终导致 Apache 崩溃(检查您的日志:$ cat/var/log/apache2/access.log).Apache 自动重新启动,但没有足够的空闲内存来重新启动 MySQL,因此出现数据库连接错误.简短的解决方法是减少 Apache 中 RequestWorker 的数量,以更好地适应您拥有的 RAM 量.

I had a similar issue with intermittent crashing of MySQL. It turned out to be Apache configurations. Bots were brute forcing the site and eventually caused Apache to crash (check your logs: $ cat /var/log/apache2/access.log). Apache automatically restarts, but there isn't enough spare memory to restart MySQL too, hence the Database Connection error. The short fix is to reduce the number of RequestWorkers in Apache to better fit the amount of RAM you have.

您可以使用 Apache2Buddy 对 apache 配置运行诊断程序.考虑到您拥有的 RAM 量和应用程序的大小,它会计算您可以运行的 Apache Worker 数量:$ curl -L http://apache2buddy.pl/|perl

You can run a diagnostic on your apache configuration using Apache2Buddy. It'll calculate how many Apache Workers you can run given the amount of RAM you have and how big your application is: $ curl -L http://apache2buddy.pl/ | perl

它可能会建议在您的 MPM-Prefork 配置中更改 MaxRequestWorkers(或旧 Apache 系统上的 MaxClients).该文件位于我系统上的 /etc/apache2/mods-available/mpm_prefork.conf.将值更改为 Apache2Buddy 推荐的值后,只需重新启动 Apache 即可.

It's probably going to recommend changing MaxRequestWorkers (or MaxClients on older Apache systems) in your MPM-Prefork configurations. That file is at /etc/apache2/mods-available/mpm_prefork.conf on my system. After changing the value to what Apache2Buddy recommends, just restart Apache and you should be good to go.

如果你想要更深入的解释、压力测试的方法或关于如何阻止一些机器人流量的想法,我写了一篇关于这种情况的文章:http://brunzino.github.io/blog/2016/05/21/solution-how-to-debug-intermittent-error-establishing-database-connection/

I wrote an article on this situation if you want a deeper explanation, a method to stress test, or ideas on how to block some of the bot traffic: http://brunzino.github.io/blog/2016/05/21/solution-how-to-debug-intermittent-error-establishing-database-connection/

这篇关于令人发狂的间歇性 Wordpress:建立数据库连接时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆