![]() |
LINUX |
logwatchのインストール
・ログをチェックし、管理者 (root) に報告します
・fedoraのパッケージをCentOS用にアレンジします
・logwatch-7.3.6-60.fc14を使っています
・スクリプト実行時のメモリ使用量をレポートします
・make はメンテナンスマシンで行っています
・ソースの取得、削除は省略します
・エディタ、ファイラーの操作は省略します
・ソースを展開したら説明文を読みましょう
・Enterキーを省略します
・ログイン端末で "#" はroot、"$" は一般ユーザのプロンプトの記号です
・設定ファイルで "#" で始まる行はコメントとして解釈されます
関連サイト| :logwatch-7.3.6-60.fc14.src.rpm | (http://ftp.riken.jp/Linux/fedora/) |
| :development | (http://logwatch.svn.sourceforge.net/) |
参照ファイル
インストール環境| :OS | CentOS 5.6 |
| :selinux | disabled or permissive |
| :インストール先 | /etc /usr/share |
| :作業 | /usr/src |
| :言語 | LANG=en_US.UTF-8 |
| :ユーザー | rootで実行 |
・メンテナンスの場合は一般ユーザから行います
logwatch-7.3.6
rebuildに必要なパッケージRequires: textutils sh-utils grep mailx Requires: perl(Date::Manip)
ソースの展開・インストール・md5チェックができないので、--nomd5オプションでインストールします
# cd /usr/src [root@jupiter:/usr/src] # mkdir logwatch # rpm -ivh --nomd5 logwatch-7.3.6-60.fc14.src.rpm # cd redhat/SPECS [root@jupiter:/usr/src/redhat/SPECS]
・specファイルの修正(下記参照)
# vi logwatch.spec # rpmbuild -ba --clean --rmsource --define 'dist .C56' logwatch.spec # mv logwatch.spec /usr/src/logwatch # cd ../RPMS/noarch [root@jupiter:/usr/src/redhat/RPMS/noarch]
・作成されたパッケージ
logwatch-7.3.6-60.C56.noarch.rpm
# mv *.rpm /usr/src/logwatch
# cd ../../SRPMS
[root@jupiter:/usr/src/redhat/SRPMS]
・作成されたパッケージ
logwatch-7.3.6-60.C56.src.rpm
# mv *.rpm /usr/src/logwatch
・インストール
# cd /usr/src/logwatch
[root@jupiter:/usr/src/logwatch]
# rpm -Uvh logwatch-7.3.6-60.C56.noarch.rpm
:/usr/src/redhat/SPECS/logwatch.spec
・logwatch-7.3.6-54.fc14.src.rpmの書式に戻しています
・紫色部分 をspecファイルに追加します
・省略
Requires: textutils sh-utils grep mailx
Requires: perl(Date::Manip)
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArchitectures: noarch
%description
・省略
configファイルの修正:/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 MailTo = root MailFrom = Logwatch Print = No Range = yesterday Detail = Med Service = All Service = "-proftpd-messages" Service = "-ftpd-xferlog" mailer = "sendmail -t"
postfixログの調整:/etc/logwatch/conf/services/postfix.conf
・既存の設定ファイルをコピーします
# cd /usr/share/logwatch/default.conf/services
[root@jupiter:/usr/share/logwatch/default.conf/services]
# cp postfix.conf /etc/logwatch/conf/services
・postfix.confの修正
・Detail (詳細度) を上げてみる
・NOQUEUEの付いたログを除く
・省略
# Yes = True = On = 1 # No = False = Off = 0
Detail = 10
Title = "postfix"
・省略
*Remove = NOQUEUE: sleep: RCPT from
*Remove = NOQUEUE: reject: RCPT from
*Remove = postfix/postscreen
*Remove = postfix/dnsblog
:/etc/logwatch/scripts/services/postfix
・既存の設定ファイルをコピーします
# cd /usr/share/logwatch/scripts/services
[root@jupiter:/usr/share/logwatch/scripts/services]
# cp postfix /etc/logwatch/scripts/services
・logwatchのpostfixレポートにはbody_checksの内容が表示されます
・body_checksの内容に接頭語(例 bdck:)を付けて表示します
・postfixでbdck:をチェックして、存在すればbody_checksを通します
・+部分 をエディタで追加します(+は書き込まない)
--- postfix.orig 2010-10-16 06:10:20.000000000 +0900 +++ postfix 2010-11-24 09:22:59.000000000 +0900 @@ -1179,6 +1179,7 @@ } $reason =~ s/\s+/ /g; + $reason =~ s/(^.)/bdck: $1/; if ($p3 =~ /^body/) { $Totals{'RejectBody'}++; $Counts{'RejectBody'}{$reason2}{$to}{formathost($hostip,$host)}{"$reason"}++;
・設定の確認
# cd ~
[root@jupiter:~]
# logwatch --service postfix --detail 10 --range all --print
# logwatch --service postfix --detail 10 --range today --print
dovecotログの調整・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.*
・省略
:/etc/logwatch/scripts/services/dovecot
・既存の設定ファイルをコピーして使います
# cd /usr/share/logwatch/scripts/services
[root@jupiter:/usr/share/logwatch/scripts/services]
# cp dovecot /etc/logwatch/scripts/services
・dovecot-2.0.xのログにあわせて修正します
・ー部分 をエディタで削除します(ーは書き込まない)
・+部分 をエディタで追加します(+は書き込まない)
--- dovecot.orig 2011-01-19 10:45:57.000000000 +0900 +++ dovecot 2011-01-19 14:06:28.000000000 +0900 @@ -66,7 +66,7 @@ while (defined($ThisLine =)) { # We don't care about these } elsif ( $ThisLine =~ /Killed with signal /) { $End++; - } elsif ( $ThisLine =~ /Dovecot (v\d[^ ]* |)starting up$/) { + } elsif ( $ThisLine =~ /Dovecot (v\d[^ ]* |)starting up /) { $Restarts++; $End = 0; } elsif ( ($User, $Host) = ( $ThisLine =~ /^pop3-login: Login: (.*?) \[(.*)\]/ ) ) {
・設定の確認
# cd ~
[root@jupiter:~]
# logwatch --service dovecot --detail 10 --range all --print
# logwatch --service dovecot --detail 10 --range today --print
proftpd(Systemlog)ログの調整・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');
・省略
・設定の確認
# cd ~
[root@jupiter:~]
# logwatch --service proftpd --detail 5 --range all --print
# logwatch --service proftpd --detail 5 --range today --print
proftpd(Transferlog)ログの調整・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
・省略
:/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');
・省略
・設定の確認
# cd ~ [root@jupiter:~] # logwatch --service proftpd-xferlog --detail 15 --range all --print # logwatch --service proftpd-xferlog --detail 15 --range today --print
sshdログの調整:/etc/logwatch/scripts/services/sshd
・既存の設定ファイルをコピーして使います
# cd /usr/share/logwatch/scripts/services
[root@jupiter:/usr/share/logwatch/scripts/services]
# cp sshd /etc/logwatch/scripts/services
・sshd-5.6のログにあわせて修正します
・+部分 をエディタで追加します(+は書き込まない)
--- sshd.orig 2010-11-22 17:05:54.000000000 +0900 +++ sshd 2010-11-26 09:13:27.000000000 +0900 @@ -225,6 +225,8 @@ ($ThisLine =~ m/^pam_ldap: ldap_starttls_s: Can't contact LDAP server/) or ($ThisLine =~ m/^\(pam_unix\) .*/) or ($ThisLine =~ m/^pam_unix\(.*:.*\)/) or + ($ThisLine =~ m/^User child is on pid/) or + ($ThisLine =~ m/^Set \/proc\/self\/oom_adj/) or # We won't count the following two because they're always followed by a # failed login entry... ($ThisLine =~ /^input_userauth_request: (illegal|invalid) user (.*)$/ ) or
・設定の確認
# cd ~
[root@jupiter:~]
# logwatch --service sshd --detail 5 --range all --print
# logwatch --service sshd --detail 5 --range today --print
メモリの情報:/etc/logwatch/conf/services/zz-meminfo.conf
・既存のzz-sys.confをコピーして使います
・cronでlogwatchを実行した時点でのメモリ使用量なので参考程度
# cd /usr/share/logwatch/default.conf/services
[root@jupiter:/usr/share/logwatch/default.conf/services]
# cp zz-sys.conf /etc/logwatch/conf/services/zz-meminfo.conf
:/etc/logwatch/scripts/services/zz-meminfo
・新しく作成します
my ($mem_total, $mem_free, $mem_used, $mem_buffers, $mem_cached);
foreach my $line (`cat /proc/meminfo`) {
if ($line =~ m/^MemTotal:.*?(\d+)/o) { $mem_total = $1; }
elsif ($line =~ m/^MemFree:.*?(\d+)/o) { $mem_free = $1; }
elsif ($line =~ m/^Buffers:.*?(\d+)/o) { $mem_buffers = $1; }
elsif ($line =~ m/^Cached:.*?(\d+)/o) { $mem_cached = $1; }
}
$mem_used = ($mem_total - $mem_free) - ($mem_buffers + $mem_cached);
print " Memory_total: " . (sprintf("%.0f", ($mem_total/1024))) . "MB\n";
print " Memory_used : " . (sprintf("%.0f", ($mem_used/1024))) . "MB\n";
・設定の確認
# cd ~
[root@jupiter:~]
# logwatch --service zz-meminfo --print
cronでの定期的実行:/etc/cron.daily/0logwatch
・リンクを修正します
・logrotateより先に実行したいので、頭に0(ゼロ)を付けます
# cd /etc/cron.daily
[root@jupiter:/etc/cron.daily]
# unlink 0logwatch
# ln -s /usr/share/logwatch/scripts/logwatch.pl 0logwatch
selinuxヘの対応 (selinuxが有効の場合)・新規インストールファイルのselinuxラベルを修正
[root@jupiter:~]
# restorecon -Rv /etc
logwatchメールのMIMEエンコード (参考)・MIMEエンコードの"charset"をlogwatch.confの"mail_charset"の値で変更します
・logwatch.plスクリプトに手を加えます ("mail_charset"の値を読み込む)
・+部分 をエディタで追加します(+は書き込まない)
:/usr/share/logwatch/scripts/logwatch.pl
・省略
--- logwatch.pl.orig 2011-01-19 10:45:57.000000000 +0900 +++ logwatch.pl 2011-01-21 09:44:02.000000000 +0900 @@ -1046,6 +1046,8 @@ sub initprint { } if ( $outtype_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. |

