使用 HAProxy 对 MySQL 进行负载平衡:读取通信数据包时出错?

qua*_*nta 7 mysql connection load-balancing haproxy

我已经通过 xinetd 使用 HAProxy设置了负载平衡 MySQL 从站。2 个负载均衡器共享一个由 Pacemaker 管理的虚拟 IP:

crm configure show

node SVR120-27148.localdomain
node SVR255-53192.localdomain
primitive failover-ip ocf:heartbeat:IPaddr2 \
    params ip="192.168.5.9" cidr_netmask="32" \
    op monitor interval="5s" \
    meta is-managed="true"
primitive haproxy ocf:heartbeat:haproxy \
    params conffile="/etc/haproxy/haproxy.cfg" \
    op monitor interval="30s" \
    meta is-managed="true"
colocation haproxy-with-failover-ip inf: haproxy failover-ip
order haproxy-after-failover-ip inf: failover-ip haproxy
property $id="cib-bootstrap-options" \
    dc-version="1.0.12-unknown" \
    cluster-infrastructure="openais" \
    no-quorum-policy="ignore" \
    expected-quorum-votes="2" \
    stonith-enabled="false" \
    last-lrm-refresh="1342783084"
Run Code Online (Sandbox Code Playgroud)

/etc/haproxy/haproxy.cfg

global
    log 127.0.0.1 local1 debug
    maxconn 4096
    pidfile /var/run/haproxy.pid
    daemon

defaults
    log global
    mode tcp
    option dontlognull 
    retries 3 
    option redispatch
    maxconn 2000
    contimeout 5000
    clitimeout 50000
    srvtimeout 50000

frontend FE_mysql
    bind 192.168.5.9:3307
    default_backend BE_mysql

backend BE_mysql
    mode tcp
    balance roundrobin
    option tcpka
    option httpchk
    #server mysql1 192.168.6.47:3306 weight 1 check port 9199 inter 12000 rise 3 fall 3
    server mysql2 192.168.6.248:3306 weight 1 check port 9199 inter 12000 rise 3 fall 3
    server mysql3 192.168.6.129:3306 weight 1 check port 9199 inter 12000 rise 3 fall 3
Run Code Online (Sandbox Code Playgroud)

我的问题是大部分时间通过虚拟 IP 连接,/var/log/mysqld.log不断涌入:

120719 12:59:46 [Warning] Aborted connection 17237 to db: 'db' user: 'user' host: '192.168.5.192' (Got an error 
reading communication packets) 
120719 12:59:49 [Warning] Aborted connection 17242 to db: 'db' user: 'user' host: '192.168.5.192' (Got an error 
reading communication packets) 
120719 12:59:52 [Warning] Aborted connection 17248 to db: 'db' user: 'user' host: '192.168.5.192' (Got an error 
reading communication packets) 
Run Code Online (Sandbox Code Playgroud)

(连接仍然建立)

192.168.5.192 是 HAProxy 的 IP 地址。

mysql> show global status like 'Aborted%';
+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| Aborted_clients  | 53626 |
| Aborted_connects | 400   |
+------------------+-------+
Run Code Online (Sandbox Code Playgroud)

我不认为 128M 是不够的max_allowed_packet

max_connections = 300
max_allowed_packet = 128M
Run Code Online (Sandbox Code Playgroud)

_timeout 变量:

mysql> show global variables like '%timeout';
+----------------------------+----------+
| Variable_name              | Value    |
+----------------------------+----------+
| connect_timeout            | 10       |
| delayed_insert_timeout     | 300      |
| innodb_lock_wait_timeout   | 60       |
| innodb_rollback_on_timeout | OFF      |
| interactive_timeout        | 3600     |
| lock_wait_timeout          | 31536000 |
| net_read_timeout           | 30       |
| net_write_timeout          | 60       |
| slave_net_timeout          | 3600     |
| wait_timeout               | 600      |
+----------------------------+----------+
Run Code Online (Sandbox Code Playgroud)

有什么可以导致这种情况的吗?它与HAProxy有关吗?

有什么想法吗?

小智 2

MySQL文档中给出了以下原因:

\n\n
\n

max_allowed_pa​​cket 变量值太小或者查询需要的内存多于为 mysqld 分配的内存。请参阅第 C.5.2.10 节,\n \xe2\x80\x9c 数据包太大\xe2\x80\x9d。

\n\n

在 Linux 中使用以太网协议,半双工和全双工。许多 Linux 以太网驱动程序都有这个错误。您应该通过使用 FTP 在客户端和服务器计算机之间传输一个大文件来测试此错误。如果传输进入突发-暂停-突发-暂停模式,则您将遇到 Linux 双工综合症。将网卡和集线器/交换机的双工模式切换为全双工或半双工,然后测试结果以确定最佳设置。

\n\n

线程库存在问题,导致读取中断。

\n\n

TCP/IP 配置错误。

\n\n

以太网、集线器、交换机、电缆等出现故障。这只能通过更换硬件才能正确诊断。

\n
\n\n

而且,更好地解释了:

\n\n
\n

尽管它们可能是更大问题的症状,但它们也可能是由正常(即不可预防的)网络问题引起的。

\n\n

即使它们位于同一 LAN,由于各种原因,您的应用程序服务器和数据库之间也可能会出现通信错误。在通信损坏或超时的情况下,应用程序和/或 MySQL 很可能会重试并正常工作,并且问题永远不会浮出水面或变得明显。

\n\n

根据我的经验,这些类型的消息最常见的来源是应用程序(服务器)失效、应用程序未正确终止连接或异地复制的延迟。

\n\n

它们很可能是在您在 MySQL 服务器上启用错误日志记录之前发生的。

\n
\n