前言
有时候服务器上部署了N多的服务,只知道端口号,你想知道这个服务是谁,路径在哪,这时候就需要一些命令来查询了
方法
1、命令lsof, 用法
1 2 3 4
| [root@localhost] [root@localhost]
|
1 2 3 4 5 6 7
| [root@localhost sbin] COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 8246 root 6u IPv4 64233 0t0 TCP *:http (LISTEN) nginx 8247 nobody 6u IPv4 64233 0t0 TCP *:http (LISTEN) [root@localhost sbin]
|
2、但是又的机器上没有这个losf这个命令,又无法安装,还有一种方式netstat
命令
1 2 3
| [root@localhost sbin] tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8246/nginx [root@localhost sbin]
|
8246就是进程号
3、下面我们再根据进程号查询具体的进程信息ps
命令
1 2 3 4 5 6 7 8 9
| [root@localhost sbin] root 8246 1 0 14:56 ? 00:00:00 nginx: master process ./nginx nobody 8247 8246 0 14:56 ? 00:00:00 nginx: worker process root 8461 2679 0 15:26 pts/1 00:00:00 grep 8246 [root@localhost sbin] Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ 8246 ? Ss 0:00 nginx: master process ./nginx 8463 pts/1 S+ 0:00 grep 8246 [root@localhost sbin]
|
结语
以上就是两种查询方式,非常有用,有时候你不知道机器上部署了什么服务,但是知道端口号,这就非常有用了