在 CentOS 上用 nohup 启动程序后,通常会把输出重定向到日志文件(如 nohup.out 或自定义日志)。监控日志常见做法如下:
tail -f nohup.out
或自定义日志:
tail -f /path/to/app.log
退出:Ctrl + C
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
如果你能告诉我:
我可以给你更精确的监控方案(如 systemd、supervisor、ELK)。