Tidb使用负载均衡时相关问题咨询

系统版本:CentOS Linux release 7.6

TiDB 版本:3.0.1

集群节点分布:生产/测试。单机单实例模式-TiDB(3)+ PD(3)+TiKV(3) 问题描述前因后果:

应用使用druid连接池获取数据库连接

尝试过HAProxy,AWS的Elastic Load Balancing 在使用负载均衡对3台tidb server做负载后应用服务器报了很多连接丢失的错误:Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

改用druid直连tidb-server的ip后此报错消失

1赞

你的haproxy的配置是怎样的?

global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon stats socket /var/lib/haproxy/stats

defaults mode tcp log global retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 180s timeout check 30s maxconn 6000

listen tidb bind *:4000 log global mode tcp balance roundrobin server tidb-1 172.31.61.204:4000 check inter 2000 rise 2 fall 3 server tidb-2 172.31.61.201:4000 check inter 2000 rise 2 fall 3 server tidb-3 172.31.61.26:4000 check inter 2000 rise 2 fall 3