我们经常会遇到,网站打不开。参看服务器运行状态会发现apache、mysql的端口被其他应用程序占用,导致程序无法启动的情况。那么如何查看linux端口号被占用的是哪一个程序呢?
无论是在Linux还是Windows上都可能会遇到端口被占用nginx、mysql、apache等程序无法启动,下面说分别说一下Linux和Windows上如何查看端口被那个程序占用。
1、Linux篇
使用命令:lsof -i:被占用的端口号

会显示出程序,及程序的PID,执行:kill 程序的PID 。
如果提示没有安装lsof这个命令,CentOS可以执行:yum install lsof 安装,Debian可以执行:apt-get install lsof 安装。
2、Windows篇
Windows上的工具比较多,如Active Ports,如果手头上没有现成的工具可以用命令:netstat -aon|findstr “80”

如下图:最后一列为程序PID,再通过tasklist命令:tasklist | findstr “2724”

再通过任务管理结束掉这个程序就可以了。