1、前言
最近在linux服务器上部署应用,总是出现端口被占用的情况,有时关闭软件,kill进程也会出现端口占用。
有时候关闭软件后,后台进程死掉,也会导致端口被占用。
2、解决方法
2.1、查找被占用的端口
命令:netstat -nultp
#netstat -nultp #查看端口使用情况
#netstat -nultp | grep 22 #只查看端口22的使用情况
linux-3v74:~ # netstat -nultp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1656/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1782/master
tcp 0 0 :::22 :::* LISTEN 1656/sshd
tcp 0 0 ::1:25 :::* LISTEN 1782/master
udp 0 0 0.0.0.0:68 0.0.0.0:* 1001/wickedd-dhcp4
linux-3v74:~ # netstat -nultp | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1656/sshd
tcp 0 0 :::22 :::* LISTEN 1656/sshd
命令: netstat -anp
#netstat -anp #查看端口使用情况
#netstat -anp | grep 22 #只查看端口22的使用情况
linux-3v74:~ # netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0