问题描述
我们的服务器,客户那边可以正常ping通,我们服务器部署了soap服务,使用的是http+tcp,使用的是tcp短链接的形式。但是我们客户端发送消息偶尔失败。
使用了psping工具,ping我们的服务器端口,发现会有ping不通的时候。
.\psping -n 10 -w 2 -h 10 www.baidu.com:80
解决流程
怀疑是客户网络线路的问题,后来ping了一下百度,发现没有丢包,才继续怀疑是我们服务器的问题(在我们公司这边psping是正常的)。
后来偶然搜到这篇文章,才知道,可能是我们服务器优化过度了。
然后将net.ipv4.tcp_tw_recycle 改成 0 就好了。
查看这个值:
cat /proc/sys/net/ipv4/tcp_tw_recycle
设置这个值:
echo 0 > /proc/sys/net/ipv4/tcp_tw_recycle
使这个值马上生效
sysctl -p
注:这里修改实际修改的是/etc/sysctl.conf 这个文件。
总结: 只要是有几个客户端(具体数量不定,如果只有一个的话肯定没有问题)在NAT后面,同时访问这个服务器,只要tcp_tw_recycle这个参数开启,就会导致tcp三次握手失败(服务器直接丢弃)。linux也不建议设置这个参数进行优化,linux 4.12版本的内核直接移除了这个参数。
The tcp_tw_recycle was already broken for connections
behind NAT, since the per-destination timestamp is not
monotonically increasing for multiple machines behind
a single destination address.
After the randomization of TCP timestamp offsets
in commit 8a5bd45f6616 (tcp: randomize tcp timestamp offsets
for each connection), the tcp_tw_recycle is broken for all
types of connections for the same reason: the timestamps
received from a single machine is not monotonically increasing,
anymore.
Remove tcp_tw_recycle, since it is not functional. Also, remove
the PAWSPassive SNMP counter since it is only used for
tcp_tw_recycle, and simplify tcp_v4_route_req and tcp_v6_route_req
since the strict argument is only set when tcp_tw_recycle is
enabled.
就这样~