CentOS 日志突然变大,通常不是单一原因,而是以下几类情况之一。你可以按需对照排查:
CentOS 7/8 默认使用 systemd-journald
原因:
排查:
journalctl --disk-usage
查看哪个服务日志最多:
journalctl -o short-precise | awk '{print $1}' | sort | uniq -c | sort -nr | head
解决:
# 限制 journal 大小
mkdir -p /etc/systemd/journald.conf.d
cat > /etc/systemd/journald.conf.d/size.conf <<EOF
[Journal]
SystemMaxUse=500M
SystemKeepFree=1G
EOF
systemctl restart systemd-journald
/var/log/messages、secure 突然变大
原因:
排查:
ls -lh /var/log/
du -sh /var/log/*
看 secure 示例:
tail -f /var/log/secure
如:
表现:
/var/log/nginx/access.log 巨大logrotate排查:
lsof | grep deleted
du -sh /var/log/*
解决:
logrotate常见原因:
检查:
systemctl status crond
ls /etc/logrotate.d/
手动执行测试:
logrotate -d /etc/logrotate.conf
logrotate -f /etc/logrotate.conf
日志删了但空间没释放
lsof | grep deleted
重启对应进程即可释放。
df -h
df -i
inode 满也会导致日志异常。
排查:
top
netstat -antup
journalctl -p err -x
df -h
du -sh /var/log/*
journalctl --disk-usage
ls -lh /var/log/
如果你能贴出:
du -sh /var/log/* 的结果我可以帮你精准判断原因。