温馨提示×

nodejs崩溃debian日志怎么查

小樊
39
2026-09-19 08:57:42
栏目: 编程语言

在 Debian 上排查 Node.js 崩溃,通常可以从以下几个地方查日志和定位问题:


1. 系统日志(systemd)

如果 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


2. Node.js 自身崩溃日志

Node.js 崩溃时通常会输出到 stderr,常见包括:

  • Error: ...
  • TypeError: ...
  • UnhandledPromiseRejectionWarning
  • Segmentation fault (core dumped)

如果是手动运行:

node app.js 2> error.log

然后查看:

cat error.log

3. Core Dump(段错误)

如果是 Segmentation fault

查看是否生成 core 文件

ulimit -c

若为 0,需开启:

ulimit -c unlimited

查找 core 文件

ls -lh /var/crash/
ls -lh core*

使用 gdb 分析

gdb node core
bt

4. /var/log 下常见日志

/var/log/syslog
/var/log/messages
/var/log/kern.log   # 内核/段错误

查看 Node 相关:

grep -i node /var/log/syslog

5. PM2(如果你用了)

pm2 logs
pm2 describe <id>
pm2 report

6. 常见排查建议

  • 捕获未处理异常:
process.on('uncaughtException', e => {
  console.error(e);
});
process.on('unhandledRejection', e => {
  console.error(e);
});
  • 使用 --trace-warnings
  • 升级 Node.js 版本

如果你愿意,可以贴出:

  • 启动方式(systemd / pm2 / 手动)
  • 报错信息或日志片段

我可以帮你更精确分析。

0