在MAC下启动某个NODE应用时,报错
Port 8021 is already in use
但使用
lsof -i tcp:8021
却无任何现实
重启过无数次,还是一样,到底是什么鬼?
后来终于找到端口的使用者,但怎么清,貌似权限不够
sudo lsof -n -P|grep :8021
launchd 1 root 7u IPv6 0xd801a7a2b2bdf8f5 0t0 TCP [::1]:8021 (LISTEN)
launchd 1 root 15u IPv4 0xd801a7a2b2be5e15 0t0 TCP 127.0.0.1:8021 (LISTEN)
launchd 1 root 16u IPv6 0xd801a7a2b2bdf8f5 0t0 TCP [::1]:8021 (LISTEN)
launchd 1 root 17u IPv4 0xd801a7a2b2be5e15 0t0 TCP 127.0.0.1:8021 (LISTEN)
lsof -i:8021
去掉tcp试试
--
不能换个端口吗?非得跟别人抢一个?
后来还是求助了stackoverflow,有人跟我遇到了类似的问题,端口被launchd进程占用,但不知道是什么程序在用,有不能kill掉这个进程。
有人建议找相关的.plist文件
find ~/Library/LaunchAgents /Library/LaunchAgents /Library/LaunchDaemons /System/Library/LaunchAgents /System/Library/LaunchDaemons -name "*.plist" -exec grep -H 8021 "{}" \; 2>/dev/null
返回:
/System/Library/LaunchDaemons/com.apple.airportd.plist: <string>IO80211Controller</string>
/System/Library/LaunchDaemons/com.apple.eapolcfg_auth.plist: <string>/System/Library/PrivateFrameworks/EAP8021X.framework/Resources/eapolcfg_auth</string>
/System/Library/LaunchDaemons/com.apple.ftp-proxy.plist: <string>8021</string>
发现问题了,原来是最近公司无线网络不好,于是我开启了AIRPORT。于是我尝试关闭共享,重启之后8021端口就被释放了。
可见8021端口是被系统默认占用的,所以在自定义使用时最好还是绕过。
sudo kill -9
直接杀死node进程,高效直接暴力