温馨提示×

centos cleanup怎么查看日志

小樊
56
2026-09-06 05:56:36
栏目: 智能运维

在 CentOS 中,“cleanup”通常指系统清理操作(如 yum clean、journalctl --vacuum、logrotate、或手动删除日志)。查看与 cleanup 相关的日志,取决于你想看的是“清理了什么”还是“日志本身如何查看/清理”。下面按常见场景说明。


一、查看系统日志(清理前/后看日志内容)

CentOS 7/8 使用 systemd,主要用 journalctl:

# 查看全部系统日志
journalctl

# 查看本次启动后的日志
journalctl -b

# 实时查看日志
journalctl -f

# 按服务查看(如 httpd)
journalctl -u httpd

# 查看某个时间之后的日志
journalctl --since "2024-01-01 00:00:00"

二、查看 yum / dnf 清理日志

如果你执行过:

yum clean all

查看相关记录:

# yum 历史
yum history

# 详细某次操作
yum history info <ID>

日志文件:

/var/log/yum.log

三、查看 logrotate(日志清理)情况

CentOS 自动清理日志靠 logrotate:

# 手动测试(不真正执行)
logrotate -d /etc/logrotate.conf

# 强制执行
logrotate -f /etc/logrotate.conf

配置文件:

/etc/logrotate.conf
/etc/logrotate.d/

被清理的日志一般在:

/var/log/
(如 messages、secure、cron)

四、查看磁盘/日志占用(判断是否该 cleanup)

# 查看磁盘
df -h

# 查看目录大小
du -sh /var/log/*

# 查看大文件
find /var/log -type f -size +100M

五、如果你是想“清理日志后如何确认”

常见做法:

# 清理 journal 日志(保留最近 7 天)
journalctl --vacuum-time=7d

# 清理 yum 缓存
yum clean all

# 清空某个日志(谨慎)
truncate -s 0 /var/log/messages

然后查看:

journalctl --disk-usage
df -h /var

如果你能补充一下:

  • 是 系统自动 cleanup
  • 还是你 手动执行了某条清理命令
  • 或想看 某个服务的日志

我可以给你更精确的命令。

0 踩