温馨提示×

centos nohup日志怎样监控

小樊
36
2026-09-06 08:10:40
栏目: 智能运维

在 CentOS 上用 nohup 启动程序后,通常会把输出重定向到日志文件(如 nohup.out 或自定义日志)。监控日志常见做法如下:


一、实时查看日志(最常用)

1. tail -f(推荐)

tail -f nohup.out

或自定义日志:

tail -f /path/to/app.log

退出:Ctrl + C

2. tail -F(更稳,文件被重建也能跟)

tail -F app.log

适合日志被 logrotate 切割的情况。


二、查看最近内容(不实时)

tail -n 100 app.log

查看最后 100 行

head -n 50 app.log

查看最前 50 行


三、搜索关键字

grep "ERROR" app.log

实时监控错误:

tail -f app.log | grep "ERROR"

四、多日志同时监控

multitail app.log error.log

(需安装:yum install multitail


五、进程 + 日志联合监控

查看 nohup 进程:

ps -ef | grep your_app

查看进程打开的日志:

lsof -p PID

六、后台持续监控(不阻塞终端)

nohup tail -f app.log > monitor.log 2>&1 &

或使用 screen / tmux

tmux
tail -f app.log
# Ctrl+B D 退出

七、日志过大处理

du -sh nohup.out

清理(不删文件):

> nohup.out

如果你能告诉我:

  • Java / Python / Shell 程序?
  • 日志是 nohup.out 还是自定义 log
  • 是否需要 报警 / 自动重启

我可以给你更精确的监控方案(如 systemd、supervisor、ELK)。

0