ページへ戻る

− Links

 印刷 

Syslog監視 :: Nest Of Hawk

xpwiki:Syslog監視

Gentoo Linuxな生活​/システム管理関連[1]

ページ内コンテンツ
  • 運用監視
  • Syslog
  • Syslog監視ツール
    • logwatchインストール
    • 設定しましょう
    • 出力の調整
  • 最後に

運用監視 anchor.png[2]

サーバといっても、インストールして、動き出しさえすればOK!というわけではありません。動作状態は定期的に監視して、問題の発見、対処、ソフトのインストールなどせねばなりません。作ることよりも、維持することのほうが大変なんです。男と女の関係と一緒ですな。

Page Top

Syslog anchor.png[3]

SyslogはUNIXにおける動作ログを収集するスタンダードです。動作のログ、エラーのログをとるものです。で、通常はこのログを監視していればいいのですが、''ログって結構量がおおいし、その中からだと、エラーの痕跡を見逃す場合もあるのですよ。

Page Top

Syslog監視ツール anchor.png[4]

そんなわけで、Syslog監視ツールなるものがあります。

Swatch
リアルタイムで何か事があったら通知してくれるツール
logwatch
ログファイルをスキャンして、ログの要約を通知してくれるツール

と、あります。で、私が選んだのはlogwatchです。だってさぁ、四六時中サーバのそばにいるわけじゃあないからね。メールで動作状態が確認できれば一応十分なのですよ。

Page Top

logwatchインストール anchor.png[5]

emerge -b logwatch

はい、インストール終了

Page Top

設定しましょう anchor.png[6]

/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出力とちょっとあっていません。なので調整してあげる必要があります。

Page Top

出力の調整 anchor.png[7]

まず、構成から説明しますね

/etc/log.dlogwatchの設定ルート
/etc/log.d/conf設定ファイルが入っている
/etc/log.d/conf/logfiles調べるlogファイル名の設定。
/etc/log.d/conf/services調べる動作サービスの設定
/etc/log.d/scripts/実際に調べるときに使うスクリプトファイル置き場

となってます。

  • /etc/log.d/conf/logfilesにどのファイルを調べるかを書いておく。(messagesとか、maillogとか)
  • /etc/log.d/conf/servicesに、何のサービスについて、どのファイルを調べるかを書いておく。

この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がウィルスの攻撃をはじいたログも出てました。本日も安泰でした。

Page Top

最後に anchor.png[9]

logwatchを入れたから安心、というわけでは在りません。実際にlogを監視することも重要です。あくまでもログ監視作業を補完するツールであるという事をお忘れなく♪


Last-modified: 2009-08-19 (水) 00:45:52 (JST) (5336d) by maruo