nohup 默认会把输出写到 nohup.out,时间久了很容易把磁盘打满。可以按下面思路处理(先救急,再根治)。
df -h # 看哪个分区满了
du -sh * | sort -hr # 找大文件
常见罪魁祸首:
nohup.out
✅ 推荐做法
: > nohup.out
# 或
truncate -s 0 nohup.out
不要直接
rm nohup.out,否则进程仍持有文件句柄,磁盘空间不会释放。
lsof | grep deleted
找到对应进程后:
kill -9 PID
# 或重启进程
nohup java -jar app.jar >/dev/null 2>&1 &
或只保留错误日志:
nohup java -jar app.jar >/dev/null 2>error.log &
nohup java -jar app.jar > app.log 2>&1 &
配合 logrotate(示例):
/opt/app/app.log {
daily
rotate 7
compress
missingok
notifempty
}
[Service]
StandardOutput=append:/var/log/app.log
StandardError=append:/var/log/app.log
systemd 可自动管理日志大小。
# 查看 nohup.out 大小
ls -lh nohup.out
# 实时查看
tail -f nohup.out
# 查看进程
ps -ef | grep nohup
✅ 救急
: > nohup.out
✅ 启动别再写 nohup.out
> /dev/null 2>&1
✅ 生产环境用 systemd / logrotate
如果你愿意,可以把你的启动命令贴出来,我可以帮你改成最合理的写法。