haproxy 负载rabbitmq集群 报client unexpectedly closed TCP connection

2024-09-30 282 0

haproxy 配置

global
        stats socket    /var/run/haproxy.socket mode 600 level admin
        log             127.0.0.1 local1 info
        user            haproxy
        group           haproxy
        chroot          /var/lib/haproxy
        daemon
        maxconn         60000

defaults
        log global
        mode tcp
        option tcplog
        option dontlognull
        option redispatch
        retries 3
        maxconn 60000
        timeout connect 5000
        timeout client 50000
        timeout server 50000

listen rabbitmq_cluster
        bind 0.0.0.0:5672
        mode tcp
        balance roundrobin
        timeout client  3h
        timeout server  3h
        server rmq107 192.168.1.107:5672 check inter 5000 rise 2 fall 3 weight 1
        server rmq108 192.168.1.108:5672 check inter 5000 rise 2 fall 3 weight 1
        server rmq109 192.168.1.109:5672 check inter 5000 rise 2 fall 3 weight 1 

listen rabbitmq_web
        bind 0.0.0.0:15672
        mode http
        balance source
        ###option httpchk GET /index.html # 请勿开启健康检测,开启会导致rabbitmq无限重启
        server rmq107 192.168.1.107:15672 check inter 3000 rise 2 fall 2 weight 1
        server rmq108 192.168.1.108:15672 check inter 3000 rise 2 fall 2 weight 1 backup
        server rmq109 192.168.1.109:15672 check inter 3000 rise 2 fall 2 weight 1 backup

php日志 报错

[AMQPException]
Library error: connection closed unexpectedly

rabbitmq日志报错

client unexpectedly closed TCP connection
2024-09-30 15:25:08.974 [info] <0.826.2536> accepting AMQP connection <0.826.2536> (192.168.1.200:60092 -> 192.168.1.35:5672)
2024-09-30 15:25:08.976 [info] <0.826.2536> connection <0.826.2536> (192.168.1.200:60092 -> 192.168.1.35:5672): user 'xyx' authenticated and granted access to vhost 'www.sundayhk.com'
2024-09-30 15:25:08.985 [info] <0.826.2536> closing AMQP connection <0.826.2536> (192.168.1.200:60092 -> 192.168.1.35:5672, vhost: 'www.sundayhk.com', user: 'xyx')
2024-09-30 15:25:09.420 [warning] <0.14448.2595> closing AMQP connection <0.14448.2595> (192.168.1.200:58034 -> 192.168.1.35:5672, vhost: 'www.sundayhk.com', user: 'xyx'):
client unexpectedly closed TCP connection
2024-09-30 15:25:09.573 [info] <0.11946.2609> accepting AMQP connection <0.11946.2609> (192.168.1.200:60126 -> 192.168.1.35:5672)
2024-09-30 15:25:09.575 [info] <0.11946.2609> connection <0.11946.2609> (192.168.1.200:60126 -> 192.168.1.35:5672): user 'xyx' authenticated and granted access to vhost 'www.sundayhk.com'
2024-09-30 15:25:11.788 [warning] <0.11556.2609> closing AMQP connection <0.11556.2609> (192.168.1.200:58058 -> 192.168.1.35:5672, vhost: 'www.sundayhk.com', user: 'xyx'):
client unexpectedly closed TCP connection
2024-09-30 15:25:11.790 [info] <0.10460.2609> accepting AMQP connection <0.10460.2609> (192.168.1.200:60176 -> 192.168.1.35:5672)
2024-09-30 15:25:11.792 [info] <0.10460.2609> connection <0.10460.2609> (192.168.1.200:60176 -> 192.168.1.35:5672): user 'xyx' authenticated and granted access to vhost 'www.sundayhk.com'
2024-09-30 15:25:13.606 [info] <0.11031.2609> accepting AMQP connection <0.11031.2609> (192.168.1.200:60188 -> 192.168.1.35:5672)
2024-09-30 15:25:13.608 [info] <0.11031.2609> connection <0.11031.2609> (192.168.1.200:60188 -> 192.168.1.35:5672): user 'xyx' authenticated and granted access to vhost 'www.sundayhk.com'
2024-09-30 15:25:15.089 [warning] <0.10318.2609> closing AMQP connection <0.10318.2609> (192.168.1.200:58102 -> 192.168.1.35:5672, vhost: 'www.sundayhk.com', user: 'xyx'):
client unexpectedly closed TCP connection
2024-09-30 15:25:15.090 [info] <0.11431.2609> accepting AMQP connection <0.11431.2609> (192.168.1.200:60210 -> 192.168.1.35:5672)
2024-09-30 15:25:15.092 [info] <0.11431.2609> connection <0.11431.2609> (192.168.1.200:60210 -> 192.168.1.35:5672): user 'xyx' authenticated and granted access to vhost 'www.sundayhk.com'
2024-09-30 15:25:19.450 [info] <0.11981.2609> accepting AMQP connection <0.11981.2609> (192.168.1.200:60312 -> 192.168.1.35:5672)
2024-09-30 15:25:19.452 [info] <0.11981.2609> connection <0.11981.2609> (192.168.1.200:60312 -> 192.168.1.35:5672): user 'xyx' authenticated and granted access to vhost 'www.sundayhk.com'
2024-09-30 15:25:19.462 [info] <0.11981.2609> closing AMQP connection <0.11981.2609> (192.168.1.200:60312 -> 192.168.1.35:5672, vhost: 'www.sundayhk.com', user: 'xyx')
2024-09-30 15:25:19.895 [warning] <0.9616.2609> closing AMQP connection <0.9616.2609> (192.168.1.200:58162 -> 192.168.1.35:5672, vhost: 'www.sundayhk.com', user: 'xyx'):
client unexpectedly closed TCP connection

提示:手动杀死队列的对应进程 rabbitmq日志也会记录client unexpectedly closed TCP connection的

若PHP主动报错,则是使用haproxy等负载时,程序未开启心跳,连接超时被中断掉导致。
解决:PHP代码 开启心跳检测

https://support.huaweicloud.com/usermanual-rabbitmq/rabbitmq-ug-0004.html
https://www.rabbitmq.com/docs/heartbeats

相关文章

MacBook系统升级到Sequoia15.1 SSH密钥无权限解决
Nginx Apache CORS OPTIONS预检请求配置
windows 2012 命令行批量修改文件权限 删除
CICD持续部署 Jenkins 部署
CICD持续集成 SonarQube 代码检测部署
win11 Microsoft Store 微软账户无法登陆 0x80190001 解决

发布评论