温馨提示×

centos nohup日志怎么查启动

小樊
47
2026-09-03 03:53:26
栏目: 智能运维

在 CentOS 上用 nohup 启动程序时,通常会把输出重定向到日志文件(最常见的是 nohup.out)。下面按常见场景说明怎么查 nohup 启动日志 / 确认是否启动成功


一、nohup 默认日志在哪

如果你是这样启动的:

nohup java -jar app.jar &

默认日志会生成在当前目录下的:

nohup.out

查看日志:

tail -f nohup.out

cat nohup.out

二、自己指定了日志文件

如果你启动时指定了日志:

nohup java -jar app.jar > app.log 2>&1 &

日志就在:

app.log

查看:

tail -f app.log

三、确认 nohup 程序是否启动

1️⃣ 查进程

ps -ef | grep 程序名

例如:

ps -ef | grep app.jar

2️⃣ 查端口(如果是服务)

netstat -lntp | grep 端口号

ss -lntp | grep 端口号

四、查看 nohup 启动时间

ps -eo pid,lstart,cmd | grep app.jar

五、常见问题排查

❌ nohup.out 没内容

  • 程序没真正启动
  • 日志被重定向到其他文件
  • 程序崩溃(看 /var/log/messagesdmesg

❌ 退出终端后程序停了

确认用了 &nohup

nohup 命令 > log 2>&1 &

六、推荐更稳妥方式(systemd)

如果是长期运行服务,建议用 systemd 而不是 nohup:

/etc/systemd/system/xxx.service

然后:

journalctl -u xxx.service -f

如果你愿意,可以把你的启动命令想查的内容(启动失败?看日志?看进程?)发出来,我可以直接帮你写命令。

0