nohup 命令默认生成的日志文件 nohup.out
不会被 Linux 系统自动清理。它的处理方式取决于以下几个因素:
为避免 nohup.out 无限增长导致磁盘空间问题,建议采取以下措施:
# 清空现有 nohup.out 内容
> nohup.out
# 或者删除并重新创建
rm nohup.out && touch nohup.out
创建 /etc/logrotate.d/nohup
配置文件:
/path/to/nohup.out {
missingok
notifempty
sharedscripts
size 100M
daily
rotate 5
compress
delaycompress
postrotate
# 如果需要,可以在这里发送信号给进程重新打开日志
endscript
}
nohup command > /var/log/myapp.log 2>&1 &
考虑使用 syslog 或 journald 等专业日志工具替代 nohup.out
需要更具体的解决方案可以根据您的实际应用场景进一步探讨。