在 CentOS(或其他 Linux 系统)中使用 nohup 启动程序时,通常会把输出重定向到日志文件(默认是 nohup.out)。要“查找错误”,一般按下面几个步骤来做。
常见情况:
nohup command > output.log 2>&1 &
或
nohup command &
# 默认生成 nohup.out
查看当前目录:
ls -l nohup.out
ls -l output.log
如果是正在运行的服务:
tail -f nohup.out
# 或
tail -f output.log
退出:Ctrl + C
一般错误会包含 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
tail -n 100 nohup.out
按时间倒序看最新错误:
tail -n 500 nohup.out | grep -i error
查看退出原因:
echo $?
(只对刚退出的 shell 有效)
查看系统日志(如 OOM、崩溃):
dmesg | tail
journalctl -xe
Permission denied
Address already in use
Exception in thread "main"
Traceback (most recent call last):
command not found
nohup ./your_app > app.log 2>&1 &
这样所有错误都会进 app.log,排查更方便。
如果你愿意,可以把 nohup 启动命令 和 日志中的报错内容 贴出来,我可以帮你具体分析原因。