在 CentOS 上用 nohup 启动程序时,日志定位错误一般有下面几种常见情况和做法:
nohup 默认日志位置nohup command > output.log 2>&1 &
如果没有显式指定重定向,nohup 默认会把输出写到:
nohup.out
通常在当前工作目录下:
ls -l nohup.out
查看日志:
tail -f nohup.out
# 或
cat nohup.out
nohup.out 在哪如果你忘了在哪里启动的,可以:
ps -ef | grep your_command
假设 PID 是 12345:
ls -l /proc/12345/cwd
nohup.out 一般就在该目录下。
find / -name nohup.out 2>/dev/null
如果之前是这样启动的:
nohup command &
错误可能混在 nohup.out 里。
建议以后统一这样写:
nohup command > app.log 2>&1 &
> :标准输出2>&1 :错误也进同一个文件tail -f app.log
或只看错误:
grep -i error app.log
cat app.log
常见原因:
Java:
nohup java -jar app.jar > app.log 2>&1 &
Python:
nohup python app.py > app.log 2>&1 &
ps -ef | grep app
或:
jobs -l
nohup your_command > /var/log/app.log 2>&1 &
并配合:
tail -f /var/log/app.log
如果你愿意,可以把:
贴出来,我可以直接帮你定位具体错误。