我们最近将我们的一个网络服务器从 PHP 5.3(Debian Squeeze 软件包,使用 libmysqlclient 和 APC)升级到 PHP 5.4(Debian Wheezy,Dotdeb 软件包,使用 mysqlnd、Opcache 和 APCu)。在正常工作了将近一天之后,每个请求我们都遇到了“mysql server has gone away”错误。所有其他负载相同的服务器仍然运行 PHP 5.3 和 libmysqlclient 使用相同的 MySQL 服务器完全没有问题。在我们使用的所有服务器上:
max_execution_time = 60
default_socket_timeout = 60
在我们的 PHP 5.3 服务器上,我们没有更改任何 mysql/my.cnf 超时。我们知道 read_timeout (mysql)、wait_timeout (mysql)、default_socket_timeout (php) 和 max_execution_time (php) 的问题,但仅限于具有长时间运行查询的批处理脚本的上下文中。我们的网络服务器通常会在 300 毫秒左右做出响应,所以这些超时在这里应该不是问题。
当我们从负载平衡中删除服务器时,它变得非常奇怪,所以不再有负载,但我们仍然有 180 个繁忙的 Apache 进程。即使aapache2ctl graceful
没有改变任何东西,甚至几个小时后apache2ctl status
说:
Apache Server Status for localhost
Server Version: Apache/2.2.22 (Debian)
Server Built: Jun 16 2014 03:51:14
__________________________________________________________________
Current Time: Tuesday, 22-Jul-2014 10:17:44 CEST
Restart Time: Monday, 21-Jul-2014 18:43:37 CEST
Parent Server Generation: 26
Server uptime: 15 hours 34 minutes 6 seconds
Total accesses: 596973 - Total Traffic: 1.6 GB
CPU Usage: u6288.72 s463.96 cu.01 cs0 - 12% CPU load
10.7 requests/sec - 30.8 kB/second - 2962 B/request
176 requests currently being processed, 99 idle workers
GGGGGG_GGGGGGGGG_GG_GGGGGGGGGGGGGGGGGGGG_GGGGGG_GGGGGGGG_GGGGGGG
GGGGGGGGGG_G_GGGGGGGG_G_GG__GGGGGG_GGGGG_GGG___GG_GGGGGGGG_G_GGG
GGGGGGGGGGGG_G_GG__GG_GGG_GGGGGGGGG__GGG_GGG_G_G_GG_G_GGGGGGGGGG
GGG_GGG_GG_GGG_GG_G_GGG_______________.___._W___________________
____.___________.______.........................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
....
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
只apache2ctl restart
解决了这个问题,一切都恢复正常了。MySQL 错误是我们目前发现的唯一“有用”的错误消息。
可能是 mysqlnd、opcache 或 apcu 和 PHP 5.4.30 的问题吗?是否有任何已知问题可能导致我们所经历的行为?
或者您知道如何调试“mysql 服务器已消失”问题?