MaxScale2.0.1结合Java Druid连接池实现读写分离注意事项

现象:
程序会不定时的出现连接错误,问题bug的异常信息如下:
The last packet successfully received from the server was 116 milliseconds ago.  The last packet sent successfully to the server was 115 milliseconds ago.
java.sql.SQLException: No database selected
 
但通过客户端sqlyog/navicat连接均为正常。
----------------------------------------------------------------------

另:maxscale1.4.3有时还会出现挂起现象,4006端口直接关闭。后我们用了watch命令后台跑监控。
watch -d /bin/bash /root/sh/restart_maxsacle.sh

1234567 #!/bin/bash
 
netstat -ntlp | grep maxscale | grep 4006 > /dev/null 2>&1
 
if [ $? -eq 1 ];then
/etc/init.d/maxscale start
fi

解决:5.6以下可以直接在url上配置:autoReconnect=true
对于5.6以上的只能在jdbc的链接池里设置:

第一个设置成ture,超时自动链接,对于mysql要把第二个设置成false,不启用缓存。
以上是开发需要注意的都是一些基本的配置。
 
其目的为:每次归还连接时执行select 'x'检测连接是否有效。

猜你喜欢

转载自www.linuxidc.com/Linux/2016-11/136970.htm