Linux-怎么看哪个端口是哪个进程占用的
刚才在玩hbase,由于只有一台linux,只好以单机版启动,直接使用了内置的zk。所以就想着查看下2181端口是不是启动了。
[root@VM-0-13-centos ~]# lsof -i:2181
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 467 root 182u IPv6 102352468 0t0 TCP *:eforward (LISTEN)
java 467 root 201u IPv6 102352531 0t0 TCP VM-0-13-centos:33872->VM-0-13-centos:eforward (ESTABLISHED)
java 467 root 202u IPv6 102352532 0t0 TCP VM-0-13-centos:eforward->VM-0-13-centos:33872 (ESTABLISHED)
java 467 root 219u IPv6 102352594 0t0 TCP VM-0-13-centos:52676->VM-0-13-centos:eforward (ESTABLISHED)
java 467 root 220u IPv6 102352595 0t0 TCP VM-0-13-centos:eforward->VM-0-13-centos:52676 (ESTABLISHED)
java 467 root 240u IPv6 102354297 0t0 TCP VM-0-13-centos:33886->VM-0-13-centos:eforward (ESTABLISHED)
java 467 root 241u IPv6 102354298 0t0 TCP VM-0-13-centos:eforward->VM-0-13-centos:33886 (ESTABLISHED)
lsof -i:2181 很有用
其他查看端口被占用命令
1 以3306为例,netstat -anp |grep 3306
图1中主要看监控状态为LISTEN表示已经被占用,最后一列显示被服务mysqld占用,查看具体端口号,只要有如图这一行就表示被占用了。
2 netstat -nultp(此处不用加端口号)
该命令是查看当前所有已经使用的端口情况,如图2: