在 CentOS 上用 nohup 启动程序时,默认会把日志输出到 nohup.out,报错也通常在里面。下面是常见查看和排查方式:
nohup.out
一般就在你启动命令的当前目录下:
ls -l nohup.out
查看报错:
tail -f nohup.out
或查看最后 100 行:
tail -n 100 nohup.out
很多人会这样启动:
nohup java -jar app.jar > app.log 2>&1 &
此时 nohup.out 是空的,日志在:
app.log
查看报错:
tail -f app.log
或搜索 ERROR / Exception:
grep -i error app.log
grep -i exception app.log
如果你是这样启动的:
nohup command > output.log &
⚠️ 错误日志不会进 output.log
需要这样:
nohup command > output.log 2> error.log &
或合并:
nohup command > all.log 2>&1 &
ps -ef | grep 程序名
或
jobs -l
tail -f /var/log/messages
(CentOS 7)
journalctl -xe
dmesg | tail
看是否有 Out of memory / killed process
# 1. 找到日志
ls -l nohup.out app.log
# 2. 看最后报错
tail -n 200 nohup.out
# 3. 搜索错误
grep -i error nohup.out
grep -i exception nohup.out
nohup java -jar app.jar > app.log 2>&1 &
这样 所有报错都在 app.log 里,排查最方便。
如果你愿意,可以把:
ls 结果发出来,我可以帮你精确定位日志在哪、为什么没报错信息。