○ logwatchのインストール

*ログをチェックし、管理者 (root) に報告します
*fedoraのパッケージをCentOS用にアレンジします
*logwatch-7.3.6-51.fc13を使っています
*スクリプト実行時のメモリ使用量をレポートします
*make はメンテナンスマシンで行っています

**以降はコメントです
*ソースの取得、削除は省略します
* エディタ、ファイラーの操作は省略します
* ソースを展開したら説明文 (英文) を読みましょう
* Enterキーを省略します

*ログイン端末で "#" はroot、"$" は一般ユーザのプロンプトの記号です
*設定ファイルで "#" で始まる行はコメントとして解釈されます

○関連サイト

:logwatch-7.3.6-51.fc13.src.rpm  (http://ftp.riken.jp/Linux/fedora/)

○参照ファイル

パッケージの追加
最初の設定 (Xen)

○インストール環境

:OS CentOS 5.5
: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
# mkdir logwatch
# rpm -ivh --nomd5 logwatch-7.3.6-51.fc13.src.rpm
# cd redhat/SPECS
# rpmbuild -ba --clean --rmsource --define 'dist .C55' logwatch.spec
# mv logwatch.spec /usr/src/logwatch
# cd ../RPMS/noarch

*作成されたパッケージ
 logwatch-7.3.6-51.C55.noarch.rpm

# mv *.rpm /usr/src/logwatch
# cd ../../SRPMS

*作成されたパッケージ
 logwatch-7.3.6-51.C55.src.rpm

# mv *.rpm /usr/src/logwatch

*インストール

# cd /usr/src/logwatch
# rpm -Uvh logwatch-7.3.6-51.C55.noarch.rpm

○configファイルの修正

:/etc/logwatch/conf/logwatch.conf

*デフォルトの設定ファイルをコピーします

# cd /usr/share/logwatch
# cp default.conf/logwatch.conf /etc/logwatch/conf

*詳細なレポートを出すように設定します

LogDir = /var/log
TmpDir = /var/cache/logwatch
MailTo = root
MailFrom = Logwatch
Print = No
Range = yesterday
Detail = Med
Service = All
mailer = "sendmail -t"

○postfixログの調整

:/etc/logwatch/scripts/services/postfix

*デフォルトの設定ファイルをコピーします

# cd /usr/share/logwatch
# cp scripts/services/postfix /etc/logwatch/scripts/services

*Anonymous TLS connection を受け入れる

*省略

 ### smtpd_tls_loglevel >= 1
 # Server TLS messages
 elsif ( ($status,$host,$hostip,$type) = ($p1 =~ /^(?:(Anonymous|Trusted|Untrusted) )?TLS
 connection established from ([^[]+)\[($re_IP)\]: (.*)$/o )) {

*省略

:/etc/logwatch/conf/services/postfix.conf

*デフォルトの設定ファイルをコピーします

# cd /usr/share/logwatch
# cp default.conf/services/postfix.conf /etc/logwatch/conf/services

*Detail (詳細度) を上げてみる
*NOQUEUEの付いたログを除く

*省略

# Yes = True = On = 1
# No = False = Off = 0

Detail = 10

Title = "postfix"

*省略

*Remove = NOQUEUE: sleep: RCPT from
*Remove = NOQUEUE: reject: RCPT from

*設定の確認

# logwatch --print --service postfix

○dovecotログの調整

:/etc/logwatch/conf/logfiles/dovecot.conf

*デフォルトのmaillog.confをコピーして使います

# cd /usr/share/logwatch
# cp default.conf/logfiles/maillog.conf /etc/logwatch/conf/logfiles/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
# cp scripts/services/dovecot /etc/logwatch/scripts/services

*ファイルの修正

*省略

# This is for Dovecot 1.0 series

} elsif ( $ThisLine =~ /failed: Authentication failure/)  {
      $AuthFail{"Fail"}++;
   } elsif ( $ThisLine =~ /failed: User not known/)  {
      $AuthFail{"Unknown User"}++;
   } elsif ($ThisLine =~ /Disconnected for inactivity/) {
      $Disconnected{"Inactivity"}++;
   } elsif ($ThisLine =~ /Disconnected in IDLE/) {

*省略

   print "\n\nTotal: $LoginCount successful logins";
}

if ((keys %AuthFail) && ($Detail >= 0))  {
   print "\n\nDovecot AuthFail:";
   foreach my $Reason (sort keys %AuthFail) {
      print "\n   $Reason: $AuthFail{$Reason} Time(s)";
   }
}

if (keys %Disconnected) {
   print "\n\nDovecot disconnects:";

*省略

:/etc/logwatch/conf/services/dovecot.conf

*デフォルトの設定ファイルをコピーして使います

# cd /usr/share/logwatch
# cp default.conf/services/dovecot.conf /etc/logwatch/conf/services

*Detail (詳細度) を上げてみる

*省略

# Yes = True = On = 1
# No = False = Off = 0

Detail = 10

Title = "Dovecot"

# Which logfole group...
LogFile = dovecot

*省略

*設定の確認

# logwatch --print --service dovecot

○proftpdログの調整

:/etc/logwatch/scripts/services/proftpd-messages

*デフォルトの設定ファイルをコピーして使います

# cd /usr/share/logwatch
# cp scripts/services/proftpd-messages /etc/logwatch/scripts/services

*mod_wrapのログを受け入れる

*省略

while (defined($ThisLine = <STDIN>)) {
   if (
         ( $ThisLine =~ /^FTP session closed/ ) or
         ( $ThisLine =~ /^(ANONYMOUS )?FTP login as \'.*\' from [^ ]+ \[.*\] to .*/ ) or
         ( $ThisLine =~ /PAM\(.*\): Authentication failure/ ) or
         ( $ThisLine =~ /^data_sendfile/ ) or
         ( $ThisLine =~ /(:| \-) FTP session (closed|opened)/ ) or
         ( $ThisLine =~ /(:| \-) No certificate files found/ ) or
         ( $ThisLine =~ /FTP (no transfer|session idle) timeout, disconnected/ ) or
         ( $ThisLine =~ / masquerading as / ) or
         ( $ThisLine =~ /mod_delay\// ) or
         ( $ThisLine =~ /mod_wrap\// ) or
         ( $ThisLine =~ /using sendfile capability for transmitting data/ ) or
         ( $ThisLine =~ /FTP login timed out, disconnected/ ) or
         ( $ThisLine =~ /Preparing to chroot to directory/ ) or
         ( $ThisLine =~ /\(.*\[.*\]\)(\:| \-) no such user '.*'/ )
      ) {

*省略

*設定の確認

# logwatch --print --service proftpd-messages

○メモリの情報

:/etc/logwatch/conf/services/zz-meminfo.conf

*デフォルトのzz-sys.confをコピーして使います

# cd /usr/share/logwatch
# cp default.conf/services/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";

*設定の確認

# logwatch --print --service zz-meminfo

○cronでの定期的実行

:/etc/cron.daily/0logwatch

*リンクを修正します

# cd cron.daily
# unlink 0logwatch
# ln -s /usr/share/logwatch/scripts/logwatch.pl 0logwatch

○selinuxヘの対応 (selinuxが有効の場合)

*新規インストールファイルのselinuxラベルを修正

# restorecon -Rv /etc

○ Copyright(c) 528p.com All Rights Reserved.