Linux查看程序端口占用情況


今天發現服務器上Tomcat 8080端口起不來,老提示端口已經被占用。

使用命令:

ps -aux | grep tomcat

發現並沒有8080端口的Tomcat進程。

使用命令:netstat –apn

查看所有的進程和端口使用情況。發現下面的進程列表,其中最后一欄是PID/Program name 

clip_image002

發現8080端口被PID為9658的Java進程占用。

進一步使用命令:ps -aux | grep java,或者直接:ps -aux | grep pid 查看

clip_image004

就可以明確知道8080端口是被哪個程序占用了!然后判斷是否使用KILL命令干掉!


方法二:直接使用 netstat   -anp   |   grep  portno
即:netstat –apn | grep 8080

[test@iZwz9e1dh1nweaex8ob5b7Z config]$ netstat -apn | grep 9124
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:9124            0.0.0.0:*               LISTEN      16116/java          
tcp        0      0 10.1.210.111:9124       10.1.210.111:47300      ESTABLISHED 16116/java          
tcp        0      0 10.1.210.111:9124       119.139.198.168:48864   ESTABLISHED 16116/java          
tcp        0      0 10.1.210.111:50496      10.1.210.111:9124       ESTABLISHED 1381/./haproxy      
tcp        0      0 10.1.210.111:9124       119.139.199.153:54049   ESTABLISHED 16116/java          
tcp        0      0 10.1.210.111:9124       119.139.198.50:17536    ESTABLISHED 16116/java          
tcp        0      0 10.1.210.111:9124       119.139.199.153:49632   ESTABLISHED 16116/java          
tcp        0      0 10.1.210.111:9124       10.1.210.111:50496      ESTABLISHED 16116/java          
tcp        0      0 10.1.210.111:47300      10.1.210.111:9124       ESTABLISHED 1381/./haproxy      
[test@iZwz9e1dh1nweaex8ob5b7Z config]$ 

 

方法三:使用lsof -i:9123

[test@iZwz9e1dh1nweaex8ob5b7Z config]$ lsof -i:9124
COMMAND   PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
haproxy  1381 test    2u  IPv4 87780501      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:50496->iZwz9e1dh1nweaex8ob5b7Z:9124 (ESTABLISHED)
haproxy  1381 test    7u  IPv4 93088108      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:47300->iZwz9e1dh1nweaex8ob5b7Z:9124 (ESTABLISHED)
java    16116 test   46u  IPv4 87777810      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:9124->iZwz9e1dh1nweaex8ob5b7Z:50496 (ESTABLISHED)
java    16116 test   65u  IPv4 60877746      0t0  TCP *:9124 (LISTEN)
java    16116 test   66u  IPv4 93089929      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:9124->iZwz9e1dh1nweaex8ob5b7Z:47300 (ESTABLISHED)
java    16116 test   67u  IPv4 64856871      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:9124->119.139.198.168:48864 (ESTABLISHED)
java    16116 test   70u  IPv4 65184853      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:9124->119.139.199.153:54049 (ESTABLISHED)
java    16116 test   74u  IPv4 65184399      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:9124->119.139.199.153:49632 (ESTABLISHED)
java    16116 test   76u  IPv4 65237661      0t0  TCP iZwz9e1dh1nweaex8ob5b7Z:9124->119.139.198.50:17536 (ESTABLISHED)
[test@iZwz9e1dh1nweaex8ob5b7Z config]$ 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM