设为首页 收藏本站
查看: 1746|回复: 0

[经验分享] Haproxy: web前段调用后面的mysql数据,不定期的报错

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-7-1 08:32:47 | 显示全部楼层 |阅读模式
在部分12580项目中,我引入了haproxy做为软负载。主要为一些非关键性的业务提供服务。架构比较简单。两台web前段,通过haproxy调用后端的两台mysql(slave),主要用于搜索。不写入数据。

自从上线后,开发人员就偶尔反馈说,有时打开web页面查询数据,报错如下:
HTTP Status 500 - Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
type Exception report
message Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
一开始以为是前端web服务器的spring组件问题。后来跳过haproxy直接连接mysql数据。没有问题。说明通过haproxy才出现此问题。
下面是haproxy的配置,其实非常简单:
frontend  acdb_ms3306
        bind 192.100.2.247:3306
        mode tcp
        option tcplog
        maxconn 20000
        default_backend backacdb_ms3306

backend backacdb_ms3306
        mode tcp
        balance roundrobin

        server web01 172.200.2.3:3306 check inter 2000 fall 3
        server web02 172.200.2.5:3306 check inter 2000 fall 3

百思不得其解。只能查看日志。内容大致都是如下的各式:


192.100.2.43:50597 [30/Jun/2015:21:57:40.094] acdb_ms3306 backacdb_ms3306/web01 1/1/83378 1350324 cD 2/2/2/1/0 0/0
192.100.2.41:56074 [30/Jun/2015:21:57:40.118] acdb_ms3306 backacdb_ms3306/web02 1/1/69986 10387 cD 3/3/3/1/0 0/0

没有发现特别的地方。后来翻墙google了好多地方。发现一片文章说,修改参数tmeout client。haproxy的日志有个标示就改变了。回头在看看我的,和他一样。在上面的日志中。存在cD标志。但不知道什么意思。搜索haproxy配置文旦,说明如下:
cD   The client did not send nor acknowledge any data for as long as the
          "timeout client" delay. This is often caused by network failures on
          the client side, or the client simply leaving the net uncleanly.
那就设置长一点吧。官方解释如下:
timeout client <timeout>
  Set the maximum inactivity time on the client side.
  May be used in sections :   defaults | frontend | listen | backend
                                                  yes      |         yes   |    yes  |   no
  Arguments :
    <timeout> is the timeout value specified in milliseconds by default, but
              can be in any other unit if the number is suffixed by the unit,
              as explained at the top of this document.
这里注意,默认单位是毫秒。
我在default位置修改。
timeout client 30s      (默认配置为timeout client 1m,这里单位应该是1毫秒。)
重启haproxy。再看日志。发现如下:
192.100.2.41:40963 [30/Jun/2015:22:24:02.904] acdb_ms3306 backacdb_ms3306/web01 1/0/20509 9224 sD 2/1/1/0/0 0/0
192.100.2.41:41893 [30/Jun/2015:22:23:56.246] acdb_ms3306 backacdb_ms3306/web02 1/0/30066 11172 sD 2/1/1/0/0 0/0

标示改为sD,啥意思:
sD   The server did not send nor acknowledge any data for as long as the
          "timeout server" setting during the data phase. This is often caused
          by too short timeouts on L4 equipments before the server (firewalls,
          load-balancers, ...), as well as keep-alive sessions maintained
          between the client and the server expiring first on haproxy.
好吧,再把timeout server 改长一点

timeout server 30s          (默认配置为timeout server 1m,这里单位应该是1毫秒。)
再看日志。哈哈。都是ok的。运行了一段时间。再也没有报连接打不开的情况了。
172.200.1.9:26387 [30/Jun/2015:21:59:40.275] acdb_ms3306 backacdb_ms3306/web01 1/0/4 160 -- 0/0/0/0/0 0/0
172.200.1.9:46303 [30/Jun/2015:21:59:40.280] acdb_ms3306 backacdb_ms3306/web02 1/0/11 6094 -- 0/0/0/0/0 0/0


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-82102-1-1.html 上篇帖子: HAproxy VS Oneproxy压测报告对比图 下篇帖子: 使用HAproxy实现view connction负载均衡 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表