1、 查看指定端口占用
# 安裝依賴
yum install lsof
lsof -i:8080
#結果
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 7497 root 222u IPv4 4658155 0t0 TCP *:webcache (LISTEN)
2、 指定的端口號的進程情況
netstat -tunlp
netstat -tunlp | grep 8080
參數說明:
- -t (tcp) 僅顯示tcp相關選項
- -u (udp)僅顯示udp相關選項
- -n 拒絕顯示別名,能顯示數字的全部轉化爲數字
- -l 僅列出在Listen(監聽)的服務狀態
- -p 顯示建立相關鏈接的程序名
netstat -tunlp | grep 8080
# 結果
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd
tcp 0 0 127.0.0.1:3476 0.0.0.0:* LISTEN 26332/nvidia-docker
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 9128/sshd
tcp 0 0 0.0.0.0:5432 0.0.0.0:* LISTEN 3585/postgres
tcp6 0 0 :::8080 :::* LISTEN 20059/docker-proxy
tcp6 0 0 :::80 :::* LISTEN 11790/docker-proxy
tcp6 0 0 :::6006 :::* LISTEN 2122/python
tcp6 0 0 :::22 :::* LISTEN 9128/sshd
tcp6 0 0 :::5432 :::* LISTEN 3585/postgres
tcp6 0 0 :::6432 :::* LISTEN 12601/docker-proxy
udp 0 0 0.0.0.0:111 0.0.0.0:* 1/systemd
udp 0 0 127.0.0.1:323 0.0.0.0:* 8689/chronyd
udp6 0 0 ::1:323 :::* 8689/chronyd
3、 自動化腳本
佔位
zhanwen