在 CentOS 上用 nohup 启动程序时,通常会把输出重定向到日志文件(最常见的是 nohup.out)。下面按常见场景说明怎么查 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
ps -ef | grep 程序名
例如:
ps -ef | grep app.jar
netstat -lntp | grep 端口号
或
ss -lntp | grep 端口号
ps -eo pid,lstart,cmd | grep app.jar
/var/log/messages 或 dmesg)确认用了 & 和 nohup:
nohup 命令 > log 2>&1 &
如果是长期运行服务,建议用 systemd 而不是 nohup:
/etc/systemd/system/xxx.service
然后:
journalctl -u xxx.service -f
如果你愿意,可以把你的启动命令和想查的内容(启动失败?看日志?看进程?)发出来,我可以直接帮你写命令。