Netstat monitor a large number of established connections and TIME_WAIT connectivity problems

Source: Internet
Author: User

To view the number of network connections:

Netstat-an |wc-l

Netstat-an |grep xx |wc-l View the number of connections for a/specific IP

Netstat-an |grep time_wait|wc-l View number of connections waiting for time_wait status connections

Netstat-an |grep established |wc-l view establish a stable number of connections


View the number of connections in different states

[Email protected] ~]# Netstat-an | awk '/^tcp/{++y[$NF]} END {for (w in y) Print W, y[w]} '

LISTEN 8

Established 2400

Fin_wait1 2

TIME_WAIT 6000


See how many connections each IP has established with the server

[[email protected] ~]# Netstat-nat|awk ' {print$5} ' |awk-f: ' {print$1} ' |sort|uniq-c|sort-rn

31 45.116.147.178

20 45.116.147.186

12 23.234.45.34

11 103.56.195.17

(PS: Regular parsing: Displays the 5th column,-F: To: Split, display columns, sort sorts, uniq-c the repeating rows in the statistical sort process, sort-rn sorted by pure numbers)

View the number of connections per IP established established/time_out state

[[email protected] ~]# netstat-nat|grep Established|awk ' {print$5} ' |awk-f: ' {print$1} ' |sort|uniq-c|sort-rn

24 103.56.195.17

19 45.116.147.186

18 103.56.195.18

17 45.116.147.178



Issue 1: Resolving a large number of time_wait connections

Adjust kernel parameters When querying too many time_wait connections:/etc/sysctl.conf

Vim/etc/sysctl.conf


Add the following configuration file:

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout =


/sbin/sysctl.conf let parameters take effect, tuning complete


Detailed parameters:

1.net.ipv4.tcp_syncookies = 1 means that Syn cookies are turned on. When a SYN wait queue overflow occurs, cookies are enabled to protect against a small number of SYN attacks, the default is 0, which means close;  

2.net.ipv4.tcp_tw_reuse = 1 means turn on reuse. Allows time-wait sockets to be re-used for new TCP connections, which defaults to 0, which means shutdown;
3.net.ipv4.tcp_tw_recycle = 1 means a fast recycle of time-wait sockets in the TCP connection is turned on, and the default is 0, which means shutdown.
4.net.ipv4.tcp_fin_timeout Modify the default timeout time for the department's Jin


If the above configuration tuning performance is not ideal, you can continue to modify the configuration:

Vi/etc/sysctl.conf

Net.ipv4.tcp_keepalive_time = #表示当keepalive起用的时候, the frequency at which TCP sends keepalive messages. The default is 2 hours, which is changed to 20 minutes. Net.ipv4.ip_local_port_range = 1024x768 65000 #表示用于向外连接的端口范围. Small by default: 32768 to 61000, 1024 to 65000. Net.ipv4.tcp_max_syn_backlog = 8192 #表示SYN队列的长度, with a default of 1024, and a larger queue length of 8192, which can accommodate more network connections waiting to be connected. Net.ipv4.tcp_max_tw_buckets = #表示系统同时保持TIME_WAIT套接字的最大数量, if this number is exceeded, the time_wait socket is immediately cleared and a warning message is printed. The default is 180000, which changes to 5000. For Apache, Nginx and other servers, the parameters of the last few lines can be a good way to reduce the number of time_wait sockets, but for Squid, the effect is not small. This parameter controls the maximum number of time_wait sockets, preventing squid servers from being dragged to death by a large number of time_wait sockets.



Problem 2:established The number of connections is too large

How to resolve the request after the end of the still large number of established not released

preliminary inference server recycling session There was a problem, this is usually the server's settings are linked.

View Tomcat the configuration file Server.xml

<ConnectorPort= "8080"Protocol= "http/1.1"ConnectionTimeout= "20000"Redirectport= "8443"uriencoding= "UTF-8" />
*****

Check configuration 20000 milliseconds acceptcount= "100", obviously unreasonable, the maximum number of connections is too small bar.

So further optimization:

connectiontimeout= "20000" instead of connectiontimeout= "acceptcount=" to "100" to Acceptcount= "5000"

Optimization completed, continue to pressure measurement ...

System responsiveness has climbed, before LoadRunner error problem until overwhelming * * * and no longer appear.

ACTION.C (380): Error-26608: For "Http://www.cnlogs.com/javame", HTTP status code =504 (Gateway time-out)




Netstat monitor a large number of established connections and TIME_WAIT connectivity problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.