我在多主设置中设置了3个MariaDB服务器的集群,工作正常。 我为HaProxy添加了第四台服务器来进行负载平衡和轮询,这样我们可以有一点冗余,这也是可行的,除了1个问题。
我login到运行以下查询的HaProxy服务器上的MySQL客户端:
show variables like 'server_id';
我得到的结果,但如果我等待5秒或更多的时间,再次运行查询,我得到以下错误:
ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 52 Current database: *** NONE ***
之后,我得到的结果与不同的server_id,这表明负载平衡正在工作。 这是造成的问题是,当我尝试从我的Spring / Java应用程序连接,我可以运行查询短时间内的连接下降。 我想我是否可以在HaProxy服务器上解决这个问题,这将解决我遇到的其他问题。
编辑:添加HAPROXY.CFG
global log 127.0.0.1 local0 notice chroot /var/lib/haproxy pidfile /var/run/haproxy.pid user haproxy group haproxy maxconn 4096 daemon defaults log global retries 2 timeout connect 3000 timeout server 5000 timeout client 5000 listen mysql-cluster bind 0.0.0.0:3306 mode tcp option tcpka option mysql-check user haproxy_check balance roundrobin server mysql-1 192.168.10.241:3306 check inter 1000 rise 3 fall 1 server mysql-2 192.168.10.242:3306 check inter 1000 rise 3 fall 1 server mysql-3 192.168.10.243:3306 check inter 1000 rise 3 fall 1 listen stats bind 192.168.10.211:8080 mode http stats enable stats uri / stats realm Strictly\ Private stats auth USER:PASSWORD
对于空闲的长时间运行的会话,如在命令行上运行mysql , timeout client和timeout server太短。
它们对于一个连接数据库的Web服务器来说可能是不错的,因为连接只要需要就打开,每个页面加载都会创build一个新的连接。
要允许连接保持打开10分钟,请更改
timeout server 5000 timeout client 5000
至
timeout server 10m timeout client 10m
如果你愿意,你可以走得更高。 我有RDS群集有7个小时的超时,它工作得很好。
该文档有关于超时客户端 , 超时服务器以及用于时间说明符的简写的更多详细信息。
尝试在mariaDB中configurationmax_allowed_packet 。 这是一个相对的链接,可以解决你的问题。
http://stackoverflow.com/questions/10474922/error-2006-hy000-mysql-server-has-gone-away