もくじ
root宛メール設定
# vi /etc/aliases # trap decode to catch security attacks decode: root # Person who should get root's mail #root: marc root: marc marc: hoge@gmail.com
反映させる
# newaliases
メール送信テスト
# echo "root送信テスト" | mail -s "mail" root
Logwatchのインストール
# yum install logwatch
# vi /etc/logwatch/conf/logwatch.conf # Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf) MailTo = root LogDir = /var/log Detail = High Archives = Yes HostLimit = Yes Range = yesterday ※複数にメールを送りたい場合は MailTo = hoge@gmail.com, hoge2@gmail.com
動作テスト
※CentOS7の場合
# logwatch --output stdout
※CentOS6の場合
# logwatch --print
################### Logwatch 7.4.0 (03/01/11) #################### Processing Initiated: Tue Sep 26 22:16:23 2017 Date Range Processed: yesterday ( 2017-Sep-25 ) Period is day. Detail Level of Output: 10 Type of Output/Format: stdout / text Logfiles for Host: www.example.net ################################################################## --------------------- Disk Space Begin ------------------------ Filesystem Size Used Avail Use% Mounted on /dev/xvda1 99G 1.4G 92G 2% / devtmpfs 3.2G 0 3.2G 0% /dev ---------------------- Disk Space End ------------------------- ###################### Logwatch End #########################
メール送信テスト
# logwatch --output mail or # logwatch --mailto hoge@example.net
定期実行スクリプトの確認
# cat /etc/cron.daily/0logwatch #!/bin/sh #Set logwatch location LOGWATCH_SCRIPT="/usr/sbin/logwatch" #Add options to this line. Most options should be defined in /etc/logwatch/conf/logwatch.conf, #but some are only for the nightly cronrun such as --output mail and should be set here. #Other options to consider might be "--format html" or "--encode base64", man logwatch for more details. OPTIONS="--output mail" #Call logwatch $LOGWATCH_SCRIPT $OPTIONS exit 0
メールが飛ばない場合の対応
# yum install logwatch
下記を行う
# cat /usr/share/logwatch/default.conf/logwatch.conf >> /etc/logwatch/conf/logwatch.conf
設定を修正します。※任意
# vi /etc/logwatch/conf/logwatch.conf # Local configuration options go here (defaults are in /usr/share/logwatch/default.conf/logwatch.conf) Detail = Low ↓変更 Detail = High # ホスト名指定 HostName = www.example.com ------------------------------------------------------ ※複数にメールを送りたい場合は MailTo = hoge@gmail.com, hoge2@gmail.com ------------------------------------------------------
動作テスト
# logwatch --output stdout # logwatch --output mail