[root@dev ~]# uname -a Linux dev.egolife.com 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 13:35:02 PST 2013 x86_64 x86_64 x86_64 GNU/Linuxyum install
[root@dev ~]# yum install -y logwatch ... ... ================================================================ Installing: logwatch noarch 7.3.6-49.el6 base 297 k Installing for dependencies: perl-Date-Manip noarch 6.24-1.el6 base 1.3 M perl-YAML-Syck x86_64 1.07-4.el6 base 75 k ... ...在安裝logwatch時,會同時安裝依賴包perl-Date-Manip和perl-YAML-Syck。
[root@dev ~]# logwatch --help Usage: /usr/sbin/logwatch [--detail <level>] [--logfile <name>] [--print] [--mailto <addr>] [--archives] [--range <range>] [--debug <level>] [--save <filename>] [--help] [--version] [--service <name>] [--numeric] [--output <output_type>] [--splithosts] [--multiemail] [--no-oldfiles-log] --detail <level>: Report Detail Level - High, Med, Low or any #. --logfile <name>: *Name of a logfile definition to report on. --logdir <name>: Name of default directory where logs are stored. --service <name>: *Name of a service definition to report on. --print: Display report to stdout. --mailto <addr>: Mail report to <addr>. --archives: Use archived log files too. --save <filename>: Save to <filename>. --range <range>: Date range: Yesterday, Today, All, Help where help will describe additional options --numeric: Display addresses numerically rather than symbolically and numerically (saves a nameserver address-to-name lookup). --debug <level>: Debug Level - High, Med, Low or any #. --splithosts: Create a report for each host in syslog. --multiemail: Send each host report in a separate email. Ignored if not using --splithosts. --output <output type>: Report Format - mail, html or unformatted#. --encode: Use base64 encoding on output mail. --no-oldfiles-log: Suppress the logwatch log, which informs about the old files in logwatch tmpdir. --version: Displays current version. --help: This message. * = Switch can be specified multiple times...從以上幫助,可以看出,LogWatch整個原理就是,LogWatch 首先要知道針對哪一個服務, 從這個服務中得到需要處理的 Log 文件信息, 然後這個文件送給過濾腳本處理, 之後把處理後格式化的信息展現出。
[root@dev ~]# logwatch --service sshd --print ################### Logwatch 7.3.6 (05/19/07) #################### Processing Initiated: Fri Jun 21 08:47:19 2013 Date Range Processed: yesterday ( 2013-Jun-20 ) Period is day. Detail Level of Output: 0 Type of Output: unformatted Logfiles for Host: dev.egolife.com ################################################################## --------------------- SSHD Begin ------------------------ Failed logins from: 172.29.73.125: 2 times Received disconnect: 13: Authentication cancelled by user. : 2 Time(s) **Unmatched Entries** userauth_pubkey: unsupported public key algorithm: x509v3-sign-rsa : 2 time(s) ---------------------- SSHD End ------------------------- ###################### Logwatch End #########################配置
[root@dev ~]# rpm -ql logwatch /etc/cron.daily/0logwatch /etc/logwatch /etc/logwatch/conf /etc/logwatch/conf/ignore.conf /etc/logwatch/conf/logfiles /etc/logwatch/conf/logwatch.conf /etc/logwatch/conf/override.conf /etc/logwatch/conf/services /etc/logwatch/scripts /etc/logwatch/scripts/services /usr/sbin/logwatch /usr/share/doc/logwatch-7.3.6 ... ... /var/cache/logwatch從以上輸出,可以看出logwatch是以cron job的方式定時運行的,默認在/etc/cron.daily目錄下,即每天運行一次。
[root@dev ~]# cat /etc/cron.daily/0logwatch #!/bin/bash DailyReport=`grep -e "^[[:space:]]*DailyReport[[:space:]]*=[[:space:]]*" /usr/share/logwatch/default.conf/logwatch.conf | head -n1 | sed -e "s|^\s*DailyReport\s*=\s*||"` if [ "$DailyReport" != "No" ] && [ "$DailyReport" != "no" ] then logwatch fi主要配置文件
[root@dev ~]# tree /etc/logwatch/ /etc/logwatch/ ├── conf │ ├── ignore.conf │ ├── logfiles │ ├── logwatch.conf │ ├── override.conf │ └── services └── scripts └── services 5 directories, 3 files
/usr/share/logwatch/default.conf/logwatch.conf
文件中。/etc/logwatch/conf/services
下自定義的服務/usr/share/logwatch/default.conf/services
下。/usr/share/logwatch/default.conf/logfiles/
下。郵件通知
[root@dev ~]# less /usr/share/logwatch/default.conf/logwatch.conf # Default person to mail reports to. Can be a local account or a # complete email address. Variable Print should be set to No to # enable mail feature. MailTo = rootLogWatch默認將分析的日志報告發送給本機的root用戶,此時要查看則需登陸到服務器上,使用mail指令查看。