Linux服务器查询占用端口的进程

今天在新的服务器上部署Tomcat,发现启动成功后访问http://localhost:8080端口报404错误,在网上查了一通后怀疑有可能是8080端口号被占用了。于是使用netstat -anp | grep 8080命令查看,确实被占用了

$ netstat -anp|grep 8080
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      1351/java

从结果上看还是被一个Java程序占用了,但是回忆了半天也没想起来是哪个应用占用了8080端口,于是换用lsof -i:端口号命令做了一下尝试:

$ lsof -i:8080
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
java    1351 root   50u  IPv4  25881      0t0  TCP *:http-alt (LISTEN)

结果依然没有找到是哪个程序占用了端口,于是又去网上搜索了一圈,发现了有人推荐使用ps -ef|grep PID命令通过PID查看进程的执行文件信息,根据上面的netstat -anp|grep 8080lsof -i:8080两个命令的执行结果可以看出来,占用8080端口进程的PID是1351,执行命令后看到:

$ ps -ef|grep 1351
root      1351     1  0 Sep18 ?        00:01:02 /opt/jdk/jdk1.8.0_261/bin/java -Dzookeeper.log.dir=/opt/apache-zookeeper-3.6.2-bin/bin/../logs -Dzookeeper.log.file=zookeeper-root-server-iZ2zefpdklq0jwgbz3mc21Z.log -Dzookeeper.root.logger=INFO,CONSOLE -XX:+HeapDumpOnOutOfMemoryError -XX:OnOutOfMemoryError=kill -9 %p -cp /opt/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/target/classes:/opt/apache-zookeeper-3.6.2-bin/bin/../build/classes:/opt/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/target/lib/*.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../build/lib/*.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-prometheus-metrics-3.6.2.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-jute-3.6.2.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/zookeeper-3.6.2.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/snappy-java-1.1.7.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/slf4j-api-1.7.25.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_servlet-0.6.0.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_hotspot-0.6.0.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient_common-0.6.0.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/simpleclient-0.6.0.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-native-unix-common-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-native-epoll-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-transport-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-resolver-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-handler-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-common-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-codec-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/netty-buffer-4.1.50.Final.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/metrics-core-3.2.5.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/log4j-1.2.17.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/json-simple-1.1.1.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jline-2.14.6.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-util-9.4.24.v20191120.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-servlet-9.4.24.v20191120.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-server-9.4.24.v20191120.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-security-9.4.24.v20191120.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-io-9.4.24.v20191120.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jetty-http-9.4.24.v20191120.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/javax.servlet-api-3.1.0.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-databind-2.10.3.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-core-2.10.3.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/jackson-annotations-2.10.3.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/commons-lang-2.6.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/commons-cli-1.2.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../lib/audience-annotations-0.5.0.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../zookeeper-*.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../zookeeper-server/src/main/resources/lib/*.jar:/opt/apache-zookeeper-3.6.2-bin/bin/../conf: -Xmx1000m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/apache-zookeeper-3.6.2-bin/bin/../conf/zoo.cfg

看到这个结果终于明白了,是前几天安装Dzookeeper框架占用了8080端口,到此为止问题终于解决了。

你可能感兴趣的:(Linux服务器查询占用端口的进程)