温馨提示×

centos nohup日志怎么查错误

小樊
43
2026-09-03 03:43:26
栏目: 智能运维

在 CentOS 上用 nohup 启动程序时,日志一般有两种情况,查错误的方法如下:


一、确认 nohup 日志在哪里

常见启动方式:

nohup command > app.log 2>&1 &

nohup command &

1️⃣ 指定了日志文件

app.log

tail -f app.log

查看错误(如果有):

grep -i error app.log

2️⃣ 没指定日志文件(默认)

nohup 默认输出到:

nohup.out

一般在当前目录

ls -l nohup.out
tail -f nohup.out

二、实时查看错误日志

tail -f nohup.out

tail -f app.log

只看错误:

tail -f app.log | grep ERROR

三、程序已经退出,如何查原因

1️⃣ 看日志最后内容

tail -100 nohup.out

2️⃣ 看系统日志(如崩溃、OOM)

journalctl -xe

dmesg | tail

3️⃣ 看是否被 kill(内存不足)

grep -i "killed process" /var/log/messages

(CentOS 7 可能在 /var/log/messagesjournalctl


四、推荐的标准写法(方便查错)

nohup command > app.log 2>&1 &
  • >:标准输出
  • 2>&1:错误也写进日志
  • 方便统一查错

五、常见错误示例

  • Permission denied → 权限问题
  • command not found → 环境变量问题
  • Address already in use → 端口被占
  • No such file or directory → 路径错误

如果你愿意,可以把:

  • 启动命令
  • 日志内容(报错部分)

发出来,我可以直接帮你定位错误。

0