温馨提示×

centos nohup日志怎么查看报错

小樊
45
2026-08-04 09:36:52
栏目: 智能运维

在 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

三、查看标准错误(stderr)

如果你是这样启动的:

nohup command > output.log &

⚠️ 错误日志不会进 output.log

需要这样:

nohup command > output.log 2> error.log &

或合并:

nohup command > all.log 2>&1 &

四、查看进程是否真的在运行

ps -ef | grep 程序名

jobs -l

五、查看系统级报错(非常有用)

1️⃣ 查看系统日志

tail -f /var/log/messages

(CentOS 7)

journalctl -xe

2️⃣ 如果是 Java / Python 程序崩溃

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,排查最方便。


如果你愿意,可以把:

  • 启动命令
  • 程序类型(Java / Python / Shell)
  • 当前目录 ls 结果

发出来,我可以帮你精确定位日志在哪、为什么没报错信息

0