PHP 代码报错:
Lost connection to MySQL server at 'reading initial communication packet', system error: 111
系统测试报错:
[root@virt_host_53 config]# mysql -hxx_db.xx.com -P49711 -uphp_xx -pfvYA2JkaDJKJgu42
ERROR 2003 (HY000): Can't connect to MySQL server on 'xx_db.xx.com' (111)
ping 一下,没有问题
[root@virt_host_53 config]# ping xx_db.xx.com
PING xx_db.xx.com (10.11.80.25) xx(84) bytes of data.
64 bytes from xx_db.xx.com (10.11.80.25): icmp_seq=1 ttl=64 time=0.299 ms
64 bytes from xx_db.xx.com (10.11.80.25): icmp_seq=2 ttl=64 time=0.226 ms
本地测试OK:
[root@localhost ~]# mysql --socket=/dev/shm/mysql_6.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31326107
Server version: 5.5.23-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
果断怀疑haproxy 原因导致,端口还在:
[root@localhost ~]# netstat -tlnup |grep haproxy
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.26:3306 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 172.16.17.202:49710 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.11:49710 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.17:49710 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.15:49710 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.19:49710 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.25:49711 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.12:49711 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.19:49711 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.11:49711 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.23:49718 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.2:13306 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.11:13306 0.0.0.0:* LISTEN 13519/haproxy
tcp 0 0 10.11.80.23:13306 0.0.0.0:* LISTEN 13519/haproxy
[root@localhost ~]# /etc/init.d/haproxy restart
Stopping haproxy: [ OK ]
Starting haproxy: [ OK ]
[root@localhost ~]#
再测试:
[root@virt_host_53 config]# mysql -hxx_db.xx.com -P49711 -uphp_xx -pfvYA2JkaDJKJgu42
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31329093
Server version: 5.5.23-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
但是,后面开发说一下可以一下不可以,我看了一下ping 的都是一个IP,
nslookup 看到有两个IP, 我勒个去:
[root@virt_host_53 config]# nslookup
> xx_db.xx.com
Server: 172.16.245.5
Address: 172.16.245.5#53
Name: xx_db.xx.com
Address: 10.11.80.25
Name: xx_db.xx.com
Address: 10.11.80.23
去掉后面那个23 的IP 后恢复,另外一种方法,估计是去掉域名解析,直接用host 方式:
my.cnf 增加参数:
skip-name-resolve
没有评论:
发表评论