求助:基于HAProxy+Keepalived+MariaDB Galera的Zabbix部署故障排查
我来帮你逐个拆解这些日志里的问题,一步步搞定:
1. Galera集群COMMIT死锁问题(日志1)
查询[COMMIT]报错:[Deadlock found when trying to get lock; try restarting transaction]
Galera集群下的死锁和传统InnoDB死锁不太一样,大多是节点间事务写冲突或者并行事务时序不匹配导致的。给你几个排查方向:
- 先开启Galera的调试日志定位冲突:在
my.cnf里添加wsrep_debug=ON,重启节点后查看/var/log/mysql/error.log,能看到具体是哪些事务、哪些表引发的冲突。 - 针对Zabbix场景优化:Zabbix的历史数据写入、自动发现操作容易触发并行写,建议:
- 调大Zabbix配置的
HousekeepingFrequency,降低后台清理操作的频率,减少冲突概率 - 修改Galera参数
wsrep_retry_autocommit(默认是1),改成3,让事务自动重试几次 - 检查是否有自定义的Zabbix触发器/脚本在频繁写库,尽量合并或优化这些操作
- 调大Zabbix配置的
- 确保所有Galera节点的时间完全同步(用NTP服务),时间不一致也会导致事务时序混乱引发冲突。
2. MySQL连接中断错误(日志2)
Sep 28 13:59:41 db2 mysqld[18273]: 2020-09-28 13:59:41 101 [Warning] Aborted connection 101 to db: 'mydb' user: 'myuser' host: '192.168.1.107' (Got an error reading communication packets)
这个警告大概率是网络不稳定或者连接超时参数不匹配导致的,解决步骤:
- 先测试HAProxy到db2的网络:在HAProxy服务器上用
ping db2的IP和mysql -h db2 -u myuser -p mydb测试连接,看是否有丢包或连接中断的情况 - 调整MySQL的连接参数:在
my.cnf里添加或修改:
重启mysqld,这些参数能避免长连接被过早断开,同时支持更大的数据包传输wait_timeout=3600 interactive_timeout=3600 max_allowed_packet=64M - 调整HAProxy的后端超时:在
haproxy.cfg的backend段添加:
避免HAProxy主动断开和MySQL的连接timeout server 30m timeout connect 10s
3. HAProxy连接超时与状态异常(日志3)
Sep 28 14:01:59 hake haproxy[16785]: 192.168.1.103:36960 [28/Sep/2020:14:01:09.283] galera_cluster_frontend galera_cluster_backend/db1 1/0/50008 364 cD 13/13/12/4/0 0/0
这里的cD状态表示HAProxy主动断开了客户端连接,因为后端db1超时(50008ms已经远超默认超时时间)。解决方法:
- 先确认db1的状态:登录db1查看MySQL是否正常运行,执行
show status like 'wsrep%';确认Galera集群状态是Synced - 给HAProxy的backend添加健康检查并调整超时:
健康检查能及时把异常节点从集群中剔除,避免请求转发到故障节点backend galera_cluster_backend balance roundrobin option tcp-check tcp-check send PING\r\n tcp-check expect string PONG tcp-check send QUIT\r\n tcp-check expect string OK server db1 192.168.1.x:3306 check inter 2000 rise 2 fall 3 server db2 192.168.1.y:3306 check inter 2000 rise 2 fall 3 server db3 192.168.1.z:3306 check inter 2000 rise 2 fall 3 timeout server 30m - 同步调整前端超时
timeout client,建议和timeout server保持一致,避免客户端侧超时
4. Keepalived配置警告与SMTP错误(日志4)
Sep 28 14:05:29 hake Keepalived_vrrp[19536]: WARNING - default user 'keepalived_script' for script execution does not exist - please create.
Sep 28 14:05:29 hake Keepalived_vrrp[19536]: SECURITY VIOLATION - scripts are being executed but script_security not enabled.
Sep 28 14:05:31 hake Keepalived_vrrp[19536]: SMTP connection ERROR to [127.0.0.1]:25.
这几个都是Keepalived的基础配置问题,逐个解决:
- 创建缺失的
keepalived_script用户:useradd -r -s /sbin/nologin keepalived_script - 启用脚本安全:在
keepalived.conf的global_defs段添加:global_defs { ... script_security 2 ... }script_security 2允许执行自定义脚本,解决安全违规警告 - 截断auth_pass到8字符:把
keepalived.conf里的auth_pass改成8位以内的字符串即可消除警告 - SMTP连接错误:Keepalived默认尝试发告警邮件到本地25端口,如果你没装邮件服务器(比如postfix),可以直接禁用邮件告警:
或者配置你可用的SMTP服务器地址和收件人global_defs { ... notification_email {} ... }
建议先搞定Keepalived和HAProxy的基础配置问题,确保负载转发正常,再处理Galera集群的事务冲突和连接问题,这样能一步步缩小故障范围。
内容的提问来源于stack exchange,提问作者ofbahar




