在 Debian 上排查 Node.js 崩溃,通常可以从以下几个地方查日志和定位问题:
如果 Node.js 是通过 systemd 服务 运行的:
journalctl -u your-node-service.service -n 100 --no-pager
实时查看:
journalctl -u your-node-service.service -f
查看崩溃相关:
journalctl -u your-node-service.service | grep -i error
替换
your-node-service.service为你的服务名(如nodeapp.service)
Node.js 崩溃时通常会输出到 stderr,常见包括:
Error: ...TypeError: ...UnhandledPromiseRejectionWarningSegmentation fault (core dumped)如果是手动运行:
node app.js 2> error.log
然后查看:
cat error.log
如果是 Segmentation fault:
ulimit -c
若为 0,需开启:
ulimit -c unlimited
ls -lh /var/crash/
ls -lh core*
gdb node core
bt
/var/log/syslog
/var/log/messages
/var/log/kern.log # 内核/段错误
查看 Node 相关:
grep -i node /var/log/syslog
pm2 logs
pm2 describe <id>
pm2 report
process.on('uncaughtException', e => {
console.error(e);
});
process.on('unhandledRejection', e => {
console.error(e);
});
--trace-warnings如果你愿意,可以贴出:
我可以帮你更精确分析。