linux-SYN-netstat TIME_WAIT

Linux Web服务器连接数控制

平时检测网站服务器连接数情况,常用的如  netstat -ant |awk ‘{print $6}’|sort|uniq -c |sort -n  给出如下统计

TIME_WAIT 3699
CLOSE_WAIT 52
FIN_WAIT1 32
SYN_SENT 1
FIN_WAIT2 2
ESTABLISHED 17
SYN_RECV 45
CLOSING 6

有时会发现大量的TIME_WAIT,SYN_RECV,  CLOSE_WAIT  ,  FIN_WAIT状态,此时需要对系统参数做些调整:

vi /etc/sysctl
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 1000
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_window_scaling = 0
net.ipv4.tcp_sack = 0
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.ip_local_port_range = 1024 65000
net.core.netdev_max_backlog =8096

先执行sysctl -p 让新设置生效,然后再次执行 netstat -ant |awk ‘{print $6}’|sort|uniq -c |sort -n  给出如下统计:

TIME_WAIT 36
CLOSE_WAIT 52
FIN_WAIT1 32
SYN_SENT 1
FIN_WAIT2 2
ESTABLISHED 2700
SYN_RECV 4
CLOSING 6

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Protected by WP Anti Spam