温馨提示×

centos nohup日志怎样查找错

小樊
39
2026-09-24 10:30:17
栏目: 智能运维

在 CentOS(或其他 Linux 系统)中使用 nohup 启动程序时,通常会把输出重定向到日志文件(默认是 nohup.out)。要“查找错误”,一般按下面几个步骤来做。


1. 确认 nohup 日志文件在哪

常见情况:

nohup command > output.log 2>&1 &

或

nohup command &
# 默认生成 nohup.out

查看当前目录:

ls -l nohup.out
ls -l output.log

2. 实时查看日志(推荐)

如果是正在运行的服务:

tail -f nohup.out
# 或
tail -f output.log

退出:Ctrl + C


3. 查找错误关键字

一般错误会包含 error、Exception、ERROR、Failed 等。

grep -i error nohup.out
grep -i exception nohup.out
grep -i failed nohup.out

带行号:

grep -n -i error nohup.out

查看错误前后内容:

grep -i -A 10 -B 5 error nohup.out

4. 查看最近的日志

tail -n 100 nohup.out

按时间倒序看最新错误:

tail -n 500 nohup.out | grep -i error

5. 如果程序已经退出

查看退出原因:

echo $?

(只对刚退出的 shell 有效)

查看系统日志(如 OOM、崩溃):

dmesg | tail
journalctl -xe

6. 常见错误场景

  • 权限问题
    Permission denied
    
  • 端口占用
    Address already in use
    
  • Java / Python 异常
    Exception in thread "main"
    Traceback (most recent call last):
    
  • 找不到命令
    command not found
    

7. 建议的 nohup 写法(方便查错)

nohup ./your_app > app.log 2>&1 &

这样所有错误都会进 app.log,排查更方便。


如果你愿意,可以把 nohup 启动命令 和 日志中的报错内容 贴出来,我可以帮你具体分析原因。

0 踩