debian

Debian dmesg日志清理技巧有哪些

小樊
45
2025-09-12 21:01:13
栏目: 智能运维

以下是Debian系统中清理dmesg日志的常用技巧:

  1. 手动清空缓冲区
    使用命令 sudo dmesg -c 直接清除当前内核日志缓冲区内容。

  2. 设置定时任务自动清理
    通过 crontab -e 添加定时任务,例如每周日午夜执行 sudo dmesg -c
    0 0 * * 0 sudo dmesg -c

  3. 利用logrotate工具轮转管理

    • 安装logrotate:sudo apt-get install logrotate
    • 编辑配置文件 /etc/logrotate.d/dmesg,添加以下内容(示例为每周轮转,保留1份旧日志):
      /var/log/dmesg {
          weekly
          rotate 1
          missingok
          notifempty
          compress
          create 0644 root root
      }
      
      执行 sudo logrotate -f /etc/logrotate.conf 测试配置。
  4. 限制内核日志缓冲区大小
    编辑 /etc/sysctl.conf,添加参数限制缓冲区大小(如 log_buf_len=1M),然后执行 sudo sysctl -p 生效。

注意:清理前确保无需保留重要日志,避免影响系统故障排查。

0
看了该问题的人还看了