Nodejs 应用程序错误:使用 pm2 部署时绑定 EADDRINUSE

2023-12-30

快速应用程序部署pm2 https://github.com/Unitech/pm2

数据库是mongodb

当使用命令运行应用程序时:

NODE_ENV=production pm2 start app.js -i max

经常有错误:绑定EADDRINUSE,这是日志,当错误时,

[app err (l0)] js:1073:26
[app err (l1)]     at Object.30:1 (cluster.js:587:5)
[app err (l2)]     at handleResponse (cluster.js:171:41)
[app err (l3)]     at respond (cluster.js:192:5)
[app err (l4)]     at handleMessage (cluster.js:202:5)
[app err (l5)]     at process.EventEmitter.emit (events.js:117:20)
[app err (l6)]     at handleMessage (child_process.js:318:10)
[app err (l7)]     at child_process.js:392:7
[app err (l8)]     at process.handleConversion.net.Native.got (child_process.js:91:7)Error: bind EADDRINUSE
[app err (l9)]     at errnoException (net.js:901:11)
[app err (l10)]     at net.js:1073:26
[app err (l11)]     at Object.31:1 (cluster.js:587:5)
[app err (l12)]     at handleResponse (cluster.js:171:41)
[app err (l13)]     at respond (cluster.js:192:5)
[app err (l14)]     at handleMessage (cluster.js:202:5)
[app err (l15)]     at process.EventEmitter.emit (events.js:117:20)
[app err (l16)]     at handleMessage (child_process.js:318:10)
[app err (l17)]     at child_process.js:392:7
[app err (l18)]     at process.handleConversion.net.Native.got (child_process.js:91:7)

这导致应用程序很慢,如何解决这个问题,非常感谢


我不知道您的应用程序使用的端口。这取决于你的代码。在这个例子中,我假设端口是3000.

您需要验证该端口是否已在您的系统上占用。要做到这一点:

  • 在Linux上:sudo netstat -nltp | grep 3000
  • On OSX: sudo lsof -i -P | grep 3000

如果有结果,则需要终止该进程(kill <pid>).

你应该检查是否pm2 list返回 0 进程。此外,当您执行pm2 stopAll,套接字未释放。不要忘记做一个pm2 kill确保守护进程被杀死。

$ pm2 kill
Daemon killed
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Nodejs 应用程序错误:使用 pm2 部署时绑定 EADDRINUSE 的相关文章

随机推荐