node.js - 端口被占用,如何取消?

查看:764
本文介绍了node.js - 端口被占用,如何取消?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

在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)

解决方案

后来还是求助了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端口是被系统默认占用的,所以在自定义使用时最好还是绕过。

这篇关于node.js - 端口被占用,如何取消?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆