3

奇怪的 Nginx 的 upstream timed out 引起响应 502

 1 year ago
source link: https://blogread.cn/it/article/5448?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

奇怪的 Nginx 的 upstream timed out 引起响应 502

浏览:7165次  出处信息

今天查看我的 MogileFS 的图片集群,发现很多的日志响应 502 的错误.很是奇怪.然后细细的查看 nginx 输出的 error 的日志,发现大量的超时 upstream timed out (110: Connection timed out) while reading response header from upstream.
当时就在想难道 MogileFS 处理能力有这么差.
认真的调节了所有的 Nginx 连接后端代理的所有设置.但怎么样都没有改善.都实在快想放弃时,想到看看系统日志.
这时系统日志报了大量的如下的信息:
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
nf_conntrack: table full, dropping packet.
所以开始怀疑是这个引起的,网上找了一些参数来调节:
Centos 6 系列:

net.nf_conntrack_max = 655360
net.netfilter.nf_conntrack_max = 655350
net.netfilter.nf_conntrack_tcp_timeout_established = 1200

如上的参数,可以让这些的连接以更加小的超时来放弃记录.另外,会给增加默认的记录.
可以从

# cat /proc/net/nf_conntrack|wc -l
80385

看看当前有多少条这个记录.

当然,如果你不用 state 跟踪的功能,可以选择弃用conntrack 模块.所以就不会出现这种问题.根据上面设置完以后, Nginx 就工作正常,不在出现这种连接上的异常了.不用 Iptables 就关掉 iptables 这个就会没有.

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK