环境
EMQX 版本:5.0.20
操作系统版本:centos
重现此问题的步骤
hapoxy 配置
frontend emqx_tcp
mode tcp
option tcplog
bind *:8888
default_backend emqx_tcp_back
backend emqx_tcp_back
mode tcp
# Create a stick table for session persistence
stick-table type string len 32 size 100k expire 30m
# Use ClientID / client_identifier as persistence key
stick on req.payload(0,0),mqtt_field_value(connect,client_identifier)
server emqx1 172.19.0.1:1883 check
server emqx2 172.19.0.1:1993 check
单个设备断开重连,都是轮询连接
emqx:release-5.3
← emqx:1012-quick-fix
opened 03:42AM - 12 Jan 24 UTC
https://discourse.haproxy.org/t/stick-table-fails-when-balancing-mqtt-traffic-an… y-suggestions-or-debugging-hints/7359/6
https://askemq.com/t/topic/7358
@CrazyWisdom
We should update this blog:
https://www.emqx.com/zh/blog/mqtt-broker-clustering-part-2-sticky-session-load-balancing
经查,需使用 v2.4.x 及以上版本 HAproxy,并添加配置,等待完成数据填充
frontend mqtt_servers
bind *:1883
mode tcp
# 等待缓冲区填满,以便解析 MQTT 报文
tcp-request inspect-delay 10s
# 拒绝非 MQTT 连接
tcp-request content reject unless { req.payload(0,0),mqtt_is_valid }
default_backend mqtt_backend
1 个赞
wivwiv:
# 拒绝非 MQTT 连接
这样配置是可以的,
tcp-request inspect-delay 10s
缓冲区填充是Haproxy启动的时候执行吗?
还是说每次客户端连接都需要执行?
每次客户端连接都执行。这里配置的是最大时间,实际填充满了就立即完成,不会有太大影响。