在 CentOS 下使用 nohup 运行程序时,日志监控常见做法如下:
nohup command > nohup.out 2>&1 &
默认日志文件是:
nohup.out
(在当前工作目录)
tail -f(推荐)tail -f nohup.out
tail -n 100 nohup.out
ps -ef | grep your_command
ls -l /proc/进程PID/fd
tail -f nohup.out | grep ERROR
tail -f nohup.out | grep --color=auto ERROR
: > nohup.out
或
cat /dev/null > nohup.out
示例:
/opt/app/nohup.out {
size 100M
rotate 5
copytruncate
missingok
}
nohup java -jar app.jar > logs/app.log 2>&1 &
然后监控:
tail -f logs/app.log
jobs -l
fg %1
tail -f / less +Fnohup.out如果你愿意,可以告诉我:
我可以给你一套更完整的方案。