LINUX |
logwatchのインストール
・ログをチェックし、管理者 (root) に報告します
・fedoraのパッケージをCentOS用にアレンジします
・logwatch-7.4.0-6.20110328svn50.fc16を使っています
・postfix用に、postfix-logwatchを組み込んでいます
・make はメンテナンスマシンで行っています
・ソースの取得、削除は省略します
・エディタ、ファイラーの操作は省略します
・ソースを展開したら説明文を読みましょう
・Enterキーを省略します
・ログイン端末で "#" はroot、"$" は一般ユーザのプロンプトの記号です
・設定ファイルで "#" で始まる行はコメントとして解釈されます
:logwatch-7.4.0-*.fc16.src.rpm | (http://dl.fedoraproject.org/) |
:development | (http://logwatch.svn.sourceforge.net/) |
:postfix-logwatch-1.40.00.tgz | (http://logreporters.sourceforge.net/) |
:OS | CentOS 6.2 |
:selinux | disabled or permissive |
:インストール先 | /etc /usr/share |
:作業 | ~/src ~/rpmbuild |
:言語 | LANG=en_US.UTF-8 |
:ユーザー | rootで実行 |
・メンテナンスの場合は一般ユーザから行います
# cd ~/src [root@jupiter:~/src] # mkdir logwatch # rpm -ivh logwatch-7.4.0-6.20110328svn50.fc16.src.rpm # cd ~/rpmbuild/SPECS [root@jupiter:~/rpmbuild/SPECS] # rpmbuild -ba --clean --rmsource \ --define 'dist .C62' logwatch.spec # mv logwatch.spec ~/src/logwatch # cd ../RPMS/noarch [root@jupiter:~/rpmbuild/RPMS/noarch]
・作成されたパッケージ
logwatch-7.4.0-6.20110328svn50.C62.noarch.rpm
# mv *.rpm ~/src/logwatch
# cd ../../SRPMS
[root@jupiter:~/rpmbuild/SRPMS]
・作成されたパッケージ
logwatch-7.4.0-6.20110328svn50.C62.src.rpm
# mv *.rpm ~/src/logwatch
・インストール
# cd ~/src/logwatch
[root@jupiter:~/src/logwatch]
# rpm -Uvh logwatch-7.4.0-6.20110328svn50.C62.noarch.rpm
:/etc/logwatch/conf/logwatch.conf
・既存の設定ファイルをコピーします
# cd /usr/share/logwatch/default.conf
[root@jupiter:/usr/share/logwatch/default.conf]
# cp logwatch.conf /etc/logwatch/conf
・logwatch.confの修正
・詳細なレポートを出すように設定します
・proftpd専用の設定とだぶらないようにするため
・"proftpd-messages" "ftpd-xferlog"を除外します
LogDir = /var/log TmpDir = /var/cache/logwatch Output = stdout Format = text Encode = none MailTo = root MailFrom = Logwatch Range = yesterday Detail = Med Service = All Service = "-proftpd-messages" Service = "-ftpd-xferlog" mailer = "/usr/sbin/sendmail -t"
・postscreenに対応しているpostfix-logwatchを組み込みます
# cd ~/src [root@jupiter:~/src] # tar zxf postfix-logwatch-1.40.00.tgz # cd postfix-logwatch-1.40.00 [root@jupiter:~/src/postfix-logwatch-1.40.00] # chmod 644 postfix-logwatch postfix-logwatch.conf # cp postfix-logwatch.conf /etc/logwatch/conf/services/postfix.conf # cp postfix-logwatch /etc/logwatch/scripts/services/postfix
:/etc/logwatch/conf/services/postfix.conf
・postfix.confの修正
・Detail (詳細度) を上げてみる
・"NOQUEUE: sleep:"の付いたログを除く
・省略
Title = "Postfix"
LogFile = maillog
Detail = 10
*Remove = NOQUEUE: sleep: RCPT from
・省略
:/etc/logwatch/scripts/services/postfix
・perlスクリプトのtaintオプション (-T) を外します
・logwatchのpostfixレポートにはbody_checksの内容が表示されます
・body_checksの内容に接頭語(例 bdck:)を付けて表示します
・postfixでbdck:をチェックして、存在すればbody_checksを通します
・ー部分を除き、+部分 をエディタで追加します(+は書き込まない)
--- postfix.orig 2012-01-12 09:22:25.000000000 +0900 +++ postfix 2012-01-13 08:55:57.000000000 +0900 @@ -1,4 +1,4 @@ -#!/usr/bin/perl -T +#!/usr/bin/perl ########################################################################## # Postfix-logwatch: written and maintained by: @@ -4195,6 +4195,7 @@ #print " trigger: \"$trigger\", host: \"$host\", eto: \"$eto\", p4: \"$p4\"\n"; $trigger =~ s/\s+/ /g; + $trigger =~ s/(^.)/bdck: $1/; $trigger = '*unknown reason' if ($trigger eq ''); $eto = '*unknown' if ($eto eq '');
・設定の確認 (stdout 端末に表示)
# cd ~
[root@jupiter:~]
# logwatch --service postfix --detail 5 --range all
# logwatch --service postfix --detail 10 --range today
・メールの確認 (root宛に送信)
# cd ~
[root@jupiter:~]
# logwatch --service postfix --mailto root
・logwatchの"dovecot"は"/var/log/maillog"をチェックします
・dovecotサーバの設定に合わせて調整します
:/etc/logwatch/conf/services/dovecot.conf
・既存の設定ファイルをコピーして使います
# cd /usr/share/logwatch/default.conf/services
[root@jupiter:/usr/share/logwatch/default.conf/services]
# cp dovecot.conf /etc/logwatch/conf/services
・Detail (詳細度) を上げてみる
・省略
# Yes = True = On = 1 # No = False = Off = 0
Detail = 10
Title = "Dovecot"
# Which logfole group...
LogFile = dovecot
・省略
:/etc/logwatch/conf/logfiles/dovecot.conf
・既存のmaillog.confをコピーして使います
# cd /usr/share/logwatch/default.conf/logfiles
[root@jupiter:/usr/share/logwatch/default.conf/logfiles]
# cp maillog.conf /etc/logwatch/conf/logfiles/dovecot.conf
・dovecot.confファイルの修正
・dovecotのログを専用のdovecot.logに出力する設定のため
・省略
# What actual file? Defaults to LogPath if not absolute path....
LogFile = dovecot.log
# If the archives are searched, here is one or more line
# (optionally containing wildcards) that tell where they are...
#If you use a "-" in naming add that as well -mgt
Archive = dovecot.log.*
・省略
・設定の確認 (stdout 端末に表示)
# cd ~
[root@jupiter:~]
# logwatch --service dovecot --detail 5 --range all
# logwatch --service dovecot --detail 10 --range today
・logwatchの"proftpd-messages"は"/var/log/messages"をチェックします
・proftpdサーバの設定に合わせて調整します
:/etc/logwatch/conf/services/proftpd.conf
・新規に設定ファイルを作成します
Title = "proftpd" LogFile = proftpd *RemoveHeaders # Set this to 1 if you want to ignore unmatched FTP messages... $ftpd_ignore_unmatched = 1
:/etc/logwatch/conf/logfiles/proftpd.conf
・新規に設定ファイルを作成します
LogFile = proftpd/proftpd.log #Archive = proftpd/proftpd.log.* #*ExpandRepeats #*OnlyHost #*ApplyStdDate
:/etc/logwatch/scripts/services/proftpd
・既存の設定ファイルをコピーして使います
# cd /usr/share/logwatch/scripts/services
[root@jupiter:/usr/share/logwatch/scripts/services]
# cp proftpd-messages /etc/logwatch/scripts/services/proftpd
:/etc/logwatch/scripts/logfiles/proftpd/aplystddate
・既存の設定ファイルをコピーして使います
# mkdir -p /etc/logwatch/scripts/logfiles/proftpd
# cd /usr/share/logwatch/scripts/shared
[root@jupiter:/usr/share/logwatch/scripts/shared]
# cp applystddate /etc/logwatch/scripts/logfiles/proftpd
・applystddateの修正 (perlの日付フォーマットの部分)
・proftpdのSytemlogの日付フォーマットに合わせます
・/var/log/messages(デフォルト)の場合は必要ないです
・省略
$SearchDate = TimeFilter('%b %d %H:%M:%S');
・省略
・設定の確認 (stdout 端末に表示)
# cd ~
[root@jupiter:~]
# logwatch --service proftpd --detail 5 --range all
# logwatch --service proftpd --detail 15 --range today
・logwatchの"ftpd-xferlog"は"/var/log/xferlog"をチェックします
・proftpdサーバの設定に合わせて調整します
:/etc/logwatch/conf/service/proftpd-xferlog.conf
・既存の設定ファイルをコピーして使います
・レポートが名前順になるので、proftpdに合わせています
# cd /usr/share/logwatch/default.conf/services [root@jupiter:/usr/share/logwatch/default.conf/services] # cp ftpd-xferlog.conf /etc/logwatch/conf/services/proftpd-xferlog.conf
・proftpd-xferlog.confファイルの修正
・proftpdサーバの設定に合わせて調整します
・ファイル名までレポートするには[Detail値]を上げます
・省略
#Detail = 15
Title = "proftpd-xferlog"
・省略
:/etc/logwatch/conf/logfiles/xferlog.conf
・既存の設定ファイルをコピーして使います
# cd /usr/share/logwatch/default.conf/logfiles
[root@jupiter:/usr/share/logwatch/default.conf/logfiles]
# cp xferlog.conf /etc/logwatch/conf/logfiles
・xferlog.confの修正
・proftpdサーバの設定に合わせて調整します
・省略
LogFile = proftpd/xferlog
#Archive = proftpd/xferlog.*
・省略
:/etc/logwatch/scripts/services/proftpd-xferlog
・既存の設定ファイルをコピーして使います
# cd /usr/share/logwatch/scripts/services
[root@jupiter:/usr/share/logwatch/scripts/services]
# cp ftpd-xferlog /etc/logwatch/scripts/services/proftpd-xferlog
:/etc/logwatch/scripts/logfiles/xferlog/applydate
・既存の設定ファイルをコピーして使います
# mkdir -p /etc/logwatch/scripts/logfiles/xferlog
# cd /usr/share/logwatch/scripts/logfiles/xferlog
[root@jupiter:/usr/share/logwatch/scripts/logfiles/xferlog]
# cp applydate /etc/logwatch/scripts/logfiles/xferlog
・applydateの修正 (perlの日付フォーマットの部分)
・proftpdのTransferlogの日付フォーマットに合わせます
・/var/log/xferlog(デフォルト)の場合も修正が必要です
・省略
$SearchDate = TimeFilter('%b %d %H:%M:%S %Y');
・省略
・設定の確認 (stdout 端末に表示)
# cd ~
[root@jupiter:~]
# logwatch --service proftpd-xferlog --detail 5 --range all
# logwatch --service proftpd-xferlog --detail 15 --range today
:/etc/logwatch/scripts/services/sshd
・既存の設定ファイルをコピーして使います
# cd /usr/share/logwatch/scripts/services
[root@jupiter:/usr/share/logwatch/scripts/services]
# cp sshd /etc/logwatch/scripts/services
・openssh-5.9のログにあわせて修正します
・+部分 をエディタで追加します(+は書き込まない)
--- sshd.orig 2011-12-07 12:11:58.886591746 +0900 +++ sshd 2011-12-07 12:12:53.417999334 +0900 @@ -271,6 +271,8 @@ while (defined(my $ThisLine =)) ($ThisLine =~ m/^error: key_read: type mismatch: encoding error/) or ($ThisLine =~ m/^channel_lookup: -?\d+: bad id/) or ($ThisLine =~ m/^error: channel \d+: chan_read_failed for istate/) or + ($ThisLine =~ m/^User child is on pid/) or + ($ThisLine =~ m/^Set \/proc\/self\/oom_adj/) or # Result of setting PermitRootLogin to forced-commands-only ($ThisLine =~ m/^Root login accepted for forced command.$/) or # usually followed by a session opened for user
・設定の確認 (stdout 端末に表示)
# cd ~
[root@jupiter:~]
# logwatch --service sshd --detail 5 --range all
# logwatch --service sshd --detail 10 --range today
:/etc/cron.daily/0logwatch
#!/bin/sh
#Set logwatch location LOGWATCH_SCRIPT="/usr/sbin/logwatch"
・省略
OPTIONS="--output mail"
#Call logwatch $LOGWATCH_SCRIPT $OPTIONS
exit 0
・新規インストールファイルのselinuxラベルを修正
[root@jupiter:~]
# restorecon -Rv /etc
・MIMEエンコードの"charset"をlogwatch.confの"mail_charset"の値で変更します
・logwatch.plスクリプトに手を加えます ("mail_charset"の値を読み込む)
・+部分 をエディタで追加します(+は書き込まない)
:/usr/share/logwatch/scripts/logwatch.pl
--- logwatch.pl.orig 2011-12-07 12:15:13.500933211 +0900 +++ logwatch.pl 2011-12-07 12:18:09.634825712 +0900 @@ -1167,6 +1167,8 @@ sub initprint { #Config{output} html if ( $Config{'format'} eq "html" ) { $out_mime .= "Content-Type: text/html; charset=\"iso-8859-1\"\n\n"; + } elsif ((defined $Config{mail_charset}) && ($Config{mail_charset} ne "")) { + $out_mime .= "Content-Type: text/plain; charset=\"$Config{mail_charset}\"\n\n"; } else { $out_mime .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n\n"; }
:/etc/logwatch/conf/logwatch.conf
・省略
mail_charset = "utf-8"
#mail_charset = "iso-2022-jp"
・省略
Copyright(c) 528p.com All Rights Reserved. |