温馨提示×

Linux日志工具:Logwatch使用指南

小樊
65
2025-08-08 05:00:09
栏目: 智能运维

Logwatch使用指南

一、安装

  • Debian/Ubuntusudo apt-get install logwatch
  • CentOS/RHELsudo yum install logwatch

二、配置

配置文件路径:/etc/logwatch/conf/logwatch.conf(若为空则复制模板:/usr/share/logwatch/default.conf/logwatch.conf)。
关键参数

  • MailTo:接收报告的邮箱(支持多个,逗号分隔)。
  • Detail:报告详细程度(Low/Med/High或数字0-10,数字越大越详细)。
  • Range:日志日期范围(All/Yesterday/Today)。
  • Service:指定服务(如sshdhttpd),-服务名表示排除该服务。
  • Output:输出格式(mail/stdout/file)。

三、常用命令

  • 生成报告并发送邮件(默认每天执行):
    logwatch --range today --detail high --output mail
  • 仅查看SSH服务日志
    logwatch --service sshd --detail high --print
  • 保存报告到文件
    logwatch --range yesterday --detail med --output file --filename /tmp/logwatch.html

四、定时任务

安装后默认在/etc/cron.daily/0logwatch生成定时任务,可通过crontab -e修改执行时间。

五、注意事项

  • 需确保系统安装邮件服务(如sendmail/postfix),否则无法发送邮件。
  • 自定义脚本可放在/usr/share/logwatch/scripts/services/,需遵循工具规范。

参考来源:

0