The company's cache system has problems these days, the number of connections exceeds the limit 2048 , which causes the application to not continue to work, we need to determine which process has a high number of connections, as follows:
Find the port number of the application that is connecting to the cache server
assuming that the port number of the cache server is 11111,
#netstat –an |grep 11111 Find the application port number of the connection cache server
TCP 0 0 xx.xx.xx.xa.52878 xx.xx.xx.xb.11111 established
TCP 0 0 xx.xx.xx.xa.52968 xx.xx.xx.xb.11111 established
TCP 0 0 xx.xx.xx.xa.52952 xx.xx.xx.xb.11111 established
TCP 0 0 xx.xx.xx.xa.52876 xx.xx.xx.xb.11111 established
TCP 0 0 xx.xx.xx.xa.52852 xx.xx.xx.xb.11111 established
......
the port number of the connection cache system is 52878,52968,52962,52876,52852,... , these port numbers are very numerous and have thousands of records.
#netstat –an|grep 11111 |awk ' {print $4} ' >/tmp/netlog.txt extract these port numbers
xx.xx.xx.xa.52878
xx.xx.xx.xa.52968
xx.xx.xx.xa.52952
xx.xx.xx.xa.52876
xx.xx.xx.xa.52852
......
#vi/tmp/netlog.txt Open the /tmp/netlog.txt file using the vi editor , delete the /c7>IP address
: 1, $s/^.\{12\}//g input in non-edit mode, preceded by a space substitution for the first three characters of the IP
after editing is complete , the NetLog.txt file is left with only the port number.
Find out which process the port number corresponds to
#vi/tmp/netlog.sh scan The port number of the NetLog.txt file by line and execute the lsof command
For line in $ (cat/tmp/netlog.txt)
Do
echo "File:${line}"
Lsof–f P-i:${line}
Done
#/tmp/netlog.sh >/tmp/netout.txt executes the script file and outputs it.
#cat/tmp/netout.txt View the file to find the process number for the port
P2997
P2997
P2997
P1887
P2997
......
2997 and the 1887 is the process number, 2997 high frequency, the process connection cache more.
#ps –ef |grep2997 View the process program
This article is from "Yao XI" blog, please be sure to keep this source http://huriver.blog.51cto.com/2745601/1642153
How to find a process through a connected port