サーバといっても、インストールして、動き出しさえすればOK!というわけではありません。動作状態は定期的に監視して、問題の発見、対処、ソフトのインストールなどせねばなりません。作ることよりも、維持することのほうが大変なんです。男と女の関係と一緒ですな。
SyslogはUNIXにおける動作ログを収集するスタンダードです。動作のログ、エラーのログをとるものです。で、通常はこのログを監視していればいいのですが、''ログって結構量がおおいし、その中からだと、エラーの痕跡を見逃す場合もあるのですよ。
そんなわけで、Syslog監視ツールなるものがあります。
と、あります。で、私が選んだのはlogwatchです。だってさぁ、四六時中サーバのそばにいるわけじゃあないからね。メールで動作状態が確認できれば一応十分なのですよ。
/etc/log.dにlogwatch.confがあります。こいつを設定してやります。
#ログのある場所 LogDir = /var/log #テンポラリエリア TmpDir = /tmp #メールを送る送付先 MailTo = XXXXX #プリントアウトするかどうか Print = No #MkTempを使用するか UseMkTemp = Yes #いつのログを調査するか Range = Yesterday #ログ解析の詳細度 Detail = Low どのサービスをチェックするか Service = All #メイルになんのツールを使用するか mailer = /bin/mail
ほとんどデフォルトで問題ありません。さて、ここで問題なのは、このlogwatch、Syslogdを使った場合のRedHatなんかの設定がデフォルトになっていまして、Syslog-ngのSyslog出力とちょっとあっていません。なので調整してあげる必要があります。
まず、構成から説明しますね
/etc/log.d | logwatchの設定ルート |
/etc/log.d/conf | 設定ファイルが入っている |
/etc/log.d/conf/logfiles | 調べるlogファイル名の設定。 |
/etc/log.d/conf/services | 調べる動作サービスの設定 |
/etc/log.d/scripts/ | 実際に調べるときに使うスクリプトファイル置き場 |
となってます。
この2つでおっけーなはず。うちでは、amavis,apache,kernel,pam,postfix,samba,sshが該当してますね。
ちと例を出すと、/etc/log.d/conf/services/postfix.conf
##################################################### # $Id: postfix.conf,v 1.3 2004/02/03 03:52:18 kirk Exp $ ##################################################### # You can put comments anywhere you want to. They are effective for the # rest of the line. # this is in the format of <name> = <value>. Whitespace at the beginning # and end of the lines is removed. Whitespace before and after the = sign # is removed. Everything is case *insensitive*. # Yes = True = On = 1 # No = False = Off = 0 Title = postfix ←/etc/log.d/scripts/services/postfixを使って調べる # Which logfile group... LogFile = messages ←messagesを調べる。messagesの定義は /etc/log.d/conf/logfiles/massages.confを見ると解る # Only give lines pertaining to the postfix service... *OnlyService = "postfix/[a-zA-Z0-9]*" # *OnlyService = "postfix/smtpd" *RemoveHeaders = ##################################################### # This was written and is maintained by: # Kenneth Porter <shiva@well.com> # # Please send all comments, suggestions, bug reports, # etc, to shiva@well.com. # #####################################################
これはほとんど変更しておりません。で、次に/etc/log.d/conf/logfiles/messages.confを見てみると #####################################################
# $Id: messages.conf,v 1.17 2002/10/13 15:24:27 kirk Exp $ ##################################################### ##################################################### # This was written and is maintained by: # Kirk Bauer <kirk@kaybee.org> # # Please send all comments, suggestions, bug reports, # etc, to kirk@kaybee.org. ##################################################### # What actual file? Defaults to LogPath if not absolute path.... LogFile = messages ←ファイル名はmessages # If the archives are searched, here is one or more line # (optionally containing wildcards) that tell where they are... # Note: if these are gzipped, you need to end with a .gz even if # you use wildcards... Archive = messages.* ←固めた過去ファイルはmessages.* Archive = messages.*.gz # Expand the repeats (actually just removes them now) *ExpandRepeats ←アーカイブファイルもチェックする # Now, lets remove the services we don't care about at all... *RemoveService = talkd *RemoveService = telnetd *RemoveService = inetd *RemoveService = nfsd *RemoveService = /sbin/mingetty # Keep only the lines in the proper date range... *OnlyHost *ApplyStdDate
こんな感じ。これもデフォルトそのままです。結構簡単にいけますでしょう。で、もう一つ問題。ここで、デフォルトパッケージについてくるlogチェックスクリプトには、postfix,apache,amavis等が付いておりません。ですので、logwatchホームページのCVS[8]にアクセスしてみます。すると、追加サービスのスクリプトが落ちていますので、ダウンロードしてきて先ほどの情報を元に設定してやります。すると、追加サービスについてログをチェックしてくれるようになるわけです。さて、さっきのPostfixだと、
--------------------- postfix Begin ------------------------ 5856267 bytes transferred 89 messages sent Messages sent by: XXXXXX (uid=XX): : X Time(s) XXXXXX (uid=X): : X Time(s) Relaying denied: From unknown[211.49.139.241] to username@put_a_valid_domain.com : 1 Time(s)
さて、コレを見て解ること。誰かが不正中継を要求してきてますネ。211.49.139.241だれ?これって感じ。ほかにも、apacheがウィルスの攻撃をはじいたログも出てました。本日も安泰でした。
logwatchを入れたから安心、というわけでは在りません。実際にlogを監視することも重要です。あくまでもログ監視作業を補完するツールであるという事をお忘れなく♪
(This host) = https://femt.ddo.jp