Linux(CentOS)下分析并优化TCP参数方法

1、从CentOS服务器监控分析看TCP状态

#netstat-ano|grep<your_port>|awk-F'''{print$6}'|sort|uniq-c

9CLOSING

1760ESTABLISHED

127FIN_WAIT1

227FIN_WAIT2

56LAST_ACK

1LISTEN

18SYN_RECV

1407TIME_WAIT

发现:TIME_WAIT和FIN_WAIT状态连接数较多。

2、统计各状态实时超时情况,发现:

#netstat-ano|grep<your_port>|grepFIN_WAIT2|awk-F'''{print$8}'|awk-F/'{print$1}'|awk-F'(''{print$2}'|sort-nr|more

1>FIN_WAIT2当前超时为15s

14.80

14.69

14.59

2>FIN_WAIT1当前超时为120s

#netstat-ano|grep<your_port>|grepFIN_WAIT1|awk-F'''{print$8}'|awk-F/'{print$1}'|awk-F'(''{print$2}'|sort-nr|more

102.39

100.09

83.86

3>TIME_WAIT当前超时为60s

#netstat-ano|grep<your_port>|grepTIME_WAIT|awk-F'''{print$8}'|awk-F/'{print$1}'|awk-F'(''{print$2}'|sort-nr|more

59.98

59.90

59.85

3、当前os参数配置如下:

net.netfilter.nf_conntrack_tcp_timeout_close_wait=60=>TIME_WAIT

net.netfilter.nf_conntrack_tcp_timeout_fin_wait=120=>FIN_WAIT1

net.ipv4.tcp_fin_timeout=15=>FIN_WAIT2

net.netfilter.nf_conntrack_tcp_timeout_time_wait=120

4、【小结】

建议优化如下:

net.netfilter.nf_conntrack_tcp_timeout_close_wait=30=>TIME_WAIT

net.netfilter.nf_conntrack_tcp_timeout_fin_wait=15=>FIN_WAIT1

net.ipv4.tcp_fin_timeout=15=>FIN_WAIT2(不调整)

net.netfilter.nf_conntrack_tcp_timeout_time_wait=30