HAProxy出现"远程主机强迫关闭了一个现有的连接 " 的错误及解决
2015-12-12 14:37
549 查看
使用haproxy作为sql server 的负载均衡器。
使用了文档中的示例配置项:
timeout client 50s
timeout server 50s
采用这个配置项,有时会出现“远程主机强迫关闭了一个现有的连接”的错误。
出现这个错误的原因是:一旦sql client超过50s没有给haproxy发送数据,则haproxy会关闭这个连接,此时sql client中的以为连接还是通的,此时发送数据就会出现异常。
在查看了HAProxy的官方文档,以及mysql和sql server的文档之后,将配置改为:
timeout client 8h
timeout server 8h
之后正常了。为什么设置为8小时呢?sql server没有查到类似wait timeout的资料,于是借鉴了mysql的配置项,mysql有一个名为wait timeout的配置项,它的默认时间为8小时,这个配置项的意思是当mysql发现与客户端的tcp连接如果超过8个小时不活动的话(收发数据),那么mysql就关闭这个连接。这个配置项跟http1.1中的keep alive timeout是类似的。
参考:
Apache: Keep-alive timeout
Amount of time the server will wait for subsequent requests on a persistent connection
Mysql: wait_timeout
The number of seconds the server waits for activity on an interactive connection before closing it.
HAProxy: timeout client
The inactivity timeout applies when the client is expected to acknowledge or send data.
使用了文档中的示例配置项:
timeout client 50s
timeout server 50s
采用这个配置项,有时会出现“远程主机强迫关闭了一个现有的连接”的错误。
出现这个错误的原因是:一旦sql client超过50s没有给haproxy发送数据,则haproxy会关闭这个连接,此时sql client中的以为连接还是通的,此时发送数据就会出现异常。
在查看了HAProxy的官方文档,以及mysql和sql server的文档之后,将配置改为:
timeout client 8h
timeout server 8h
之后正常了。为什么设置为8小时呢?sql server没有查到类似wait timeout的资料,于是借鉴了mysql的配置项,mysql有一个名为wait timeout的配置项,它的默认时间为8小时,这个配置项的意思是当mysql发现与客户端的tcp连接如果超过8个小时不活动的话(收发数据),那么mysql就关闭这个连接。这个配置项跟http1.1中的keep alive timeout是类似的。
参考:
Apache: Keep-alive timeout
Amount of time the server will wait for subsequent requests on a persistent connection
Mysql: wait_timeout
The number of seconds the server waits for activity on an interactive connection before closing it.
HAProxy: timeout client
The inactivity timeout applies when the client is expected to acknowledge or send data.
相关文章推荐
- hdoj--2098--分拆素数和(水题)
- 线程的两种实现方法
- PHP中的HTML5应用 将Canvas图像保存到服务器
- AC自动机入门
- JSON转为字符串,字符串转为JSON格式
- 迟到的开始
- 我所了解的cgi
- Ubuntu14.04如何备份和恢复系统
- 静态方法的使用2——与实例化方法的区别
- 用户及权限管理
- 页面编码
- 重新启动Linux 下oracle 数据
- veridata实验例(3)验证veridata发现insert操作不会导致同步
- 求解最小生成树
- python 用xlrd及xlutils模块 复制excel文件
- 直接插入排序
- 23种设计模式
- LeetCode 226:Invert Binary Tree
- pageadmin企业建站系统为中小企业轻松搭建企业网站
- nodejs基础