Server ≫ Linux Server ≫ Fedora 8 ≫ ログを見る(LogWatch)

 
   
LogWatch
   
  自宅Webサーバーで24時間運営していると色々な攻撃にさらされます。そこで各種のログを見て対策を施すことになりますが各種をログを一つひとつ確認して行くのは大変手間の掛かることです。

そこで LogWatch と言うソフトを使い各種ログを一括して収集し、メールで管理人の元へ知らせる方法です。

   
   
LogWatchのインストール
   
  インストールと言っても Fedora7 には標準でインストールされますので設定さえすれば使えるようになります。

もし、何らかの理由でインストールされていなければ下記の要領でインストールします。

下記のように入力します。青文字が入力文字です。

   
   
 
[root@linux]# yum install logwatch    ← 入力
 fedora                    100% |=========================| 1.1 kB 00:00
 updates                   100% |=========================| 203 kB 00:00
 Setting up Install Process
 Parsing package install arguments
 Resolving Dependencies
 --> Running transaction check
 ---> Package logwatch.noarch 0:7.3.6-15.fc8 set to be updated
 --> Finished Dependency Resolution

 Dependencies Resolved

 =============================================================================
   Package          Arch           Version           Repository         Size
 =============================================================================
 Installing:
   logwatch         noarch         7.3-6-15.fc8      updates            318 k

 Transaction Summary
 =============================================================================
 Install   1 Package(s)
 Update    0 Package(s)
 Remove    0 Package(s)

 Total download size: 318 k
 Is this ok [y/N]:
y    ← y を入力
 Downloading Packages:
 (1/1): logwatch-7.3.6-15. 100% |=========================| 318 kB   00:05
 Running rpm_check_debug
 Running Transaction Test
 Finished Transaction Test
 Transaction Test Succeeded
 Running Transaction
   Installing: logwatch                    ######################### [1/1]

 Installed: logwatch.noarch 0:7.3.6-15.fc8
 Complete!
    ← Complete! と表示されればインストール完了

 
   
   
LogWatchの設定
   
  LogWatch の設定ファイルを開きます。下記のように緑色の部分を黄色に変更(書き換え・削除)して下さい。赤文字は説明です。青文字が入力文字です。
   
   
 
[root@linux]# vi /usr/share/logwatch/default.conf/logwatch.conf    ← 入力
 
 ########################################################
 # This was written and is maintained by:
 #    Kirk Bauer <kirk@kaybee.org>
 #
 # Please send all comments, suggestions, bug reports,
 #    etc, to kirk@kaybee.org.
 #
 ########################################################

 # NOTE:
 #   All these options are the defaults if you run logwatch with no
 #   command-line arguments. You can override all of these on the
 #   command-line.

 # 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

 # Default Log Directory
 # All log-files are assumed to be given relative to this directory.
 LogDir = /var/log ← ログファイルの保存場所の指定 (通常は変更の必要なし)

 # You can override the default temp directory (/tmp) here
 
TmpDir = /var/cache/logwatch ←テンポラリファイルの保存場所の指定 (通常は変更の必要なし)

 # Default person to mail reports to. Can be a local account or a
 # complete email address.
 
MailTo = root
   ↓
 
MailTo = xxx@yyyy.zzz ← メールの送信先アドレス
 # Default person to mail reports from. Can be a local account or a
 # complete email address.MailFrom = Logwatch
 MailFrom = Logwatch
 
 # If set to 'Yes', the report will be sent to stdout instead of being
 # mailed to above person.
 
Print =
   ↓
 
Print = No ← No = メール送信、Yes = コンソール表示

 # if set, the results will be saved in <filename> instead of mailed
 # or displayed.
 
#Save = /tmp/logwatch ← この行を有効にするとメール送信を行わずファイルに保存 (通常は変更の必要なし)

 # Use archives? If set to 'Yes', the archives of logfiles
 # (i.e. /var/log/messages.1 or /var/log/messages.1.gz) will
 # be searched in addition to the /var/log/messages file.
 # This usually will not do much if your range is set to just
 # 'Yesterday' or 'Today'... it is probably best used with
 
# Archives = Yes ← Yes = アーカイブされたログをチェック、No = アーカイブされたログをチェックしない (通常は変更の必要なし)
 
# Range = All ← All = 全てのログが対象、Today = 当日のログのみ対象、Yesterday = 昨日のログのみ対象 
                                           
(通常は変更の必要なし)
 # The default time range for the report...
 # The current choices are All, Today, Yesterday
 
Range = yesterday ← 昨日のログを収集 (通常は変更の必要なし)  ↑と同じ

 # This can either be Low, Med, High or a number.
 # Low = 0
 # Med = 5
 # High = 10
 
Detail = Low ← ログの詳細レベルの設定 0〜10の数字での設定も可能 (通常は変更の必要なし)

 # The 'Service' option expects either the name of a filter
 # (in /usr/share/logwatch/scripts/services/*) or 'All'.
 # The default service(s) to report on. This should be left as All for
 # most people.
 
Service = All ← 収集するサービスの設定 All = 全て   ファイルを指定することも可能 (通常は変更の必要なし)
 # You can also disable certain services (when specifying all)
 Service = "-zz-network"     # Prevents execution of zz-network service, which
                             # prints useful network configuration info.
 Service = "-zz-sys"         # Prevents execution of zz-sys service, which # prints useful system
                                                                                   configuration  info.
 Service = "-eximstats"      # Prevents execution of eximstats service, which
                             # is a wrapper for the eximstats program.
 # If you only cared about FTP messages, you could use these 2 lines
 # instead of the above:
 #Service = ftpd-messages    # Processes ftpd messages in /var/log/messages
 #Service = ftpd-xferlog     # Processes ftpd messages in /var/log/xferlog
 # Maybe you only wanted reports on PAM messages, then you would use:
 #Service = pam_pwdb         # PAM_pwdb messages - usually quite a bit
 #Service = pam              # General PAM messages... usually not many

 # You can also choose to use the 'LogFile' option. This will cause
 # logwatch to only analyze that one logfile.. for example:
 
#LogFile = messages ← 特定のログファイルのみを収集する (通常は変更の必要なし)
 # will process /var/log/messages. This will run all the filters that
 # process that logfile. This option is probably not too useful to
 # most people. Setting 'Service' to 'All' above analyizes all LogFiles
 # anyways...

 #
 # By default we assume that all Unix systems have sendmail or a sendmail-like system.
 # The mailer code Prints a header with To: From: and Subject:.
 # At this point you can change the mailer to any thing else that can handle that output
 # stream. TODO test variables in the mailer string to see if the To/From/Subject can be set
 # From here with out breaking anything. This would allow mail/mailx/nail etc..... -mgt
 
mailer = "sendmail - t" ← メーラーの指定 使用している SMTP サーバーを指定 (Postfix 等の sendmail 互換のメーラーを
   ↓                                                                  使っている場合は変更の必要なし)
 
mailer = /bin/mail ← メーラーの指定 使用している SMTP サーバーを指定 (その他のメーラーを新規導入した場合に指定)

 #
 # With this option set to 'Yes', only log entries for this particular host
 # (as returned by 'hostname' command) will be processed. The hostname
 # can also be overridden on the commandline (with --hostname option). This
 # can allow a log host to process only its own logs, or Logwatch can be
 # run once per host included in the logfiles.
 #
 # The default is to report on all log entries, regardless of its source host.
 # Note that some logfiles do not include host information and will not be
 # influenced by this setting.
 #
 
#HostLimit = Yes ← Yes = ローカルサーバーのログを収集、No = 転送されたログも含む全てのログを収集
                                    
       (通常は変更の必要なし)
 # vi: shiftwidth=3 tabstop=3 et
 
   
  基本的には上記のようにメールアドレスを指定すればOKです
   
   
ログの送信テスト
   
  記のように /usr/sbin/logwatch 入力します。
   
   
 
[root@linux]# /usr/sbin/logwatch    ← 入力
 
   
  お使いのメーラーにてメールの受信をしてみる。下記のようなメールが届いたら成功です。(例ですので環境によって違ってきます)
   
   
 ###################
Logwatch 7.3.6 (05/19/07) ####################
           
Processing Initiated: Tue Apr 29 18:12:10 2008
                             Date Range Processed: yesterday
                                        ( 2008-Apr-28 )
                                          Period is day.
                                  Detail Level of Output: 0
                               Type of Output: unformatted
                               Logfiles for Host: mail-server

 ##################################################################

 --------------------- pam_unix Begin ------------------------   ← pam_unix情報

 su:  ← su状況
  Sessions Opened
    abc (uid=500)  ->  root: 1 Time(s)  ← abc が root に1回変更

 ---------------------- pam_unix End -------------------------

 --------------------- Connections (secure-log) Begin ------------------------   ← Connections情報

 New Users:  ← ユーザー新規登録状況
  xyz (uid=501)  ← ユーザー xyz が新規登録された

 ---------------------- Connections (secure-log) End -------------------------

 --------------------- httpd Begin ------------------------   ← httpd情報

 Requests with error response codes  ← エラー状況
  401 Unauthorized  ← エラーコード401(認証エラー)
    /: 3 Time(s)  ← 3回のアクセス

 ---------------------- httpd End -------------------------

 --------------------- SSHD Begin ------------------------  ← SSH情報

 Users logging in through sshd:  ← SSHを使った接続状況
   root:  ← rootでログイン
     192.168.*.***: 1 time  ← 192.168.*.*** が 1回

 ---------------------- SSHD End -------------------------

 --------------------- yum Begin ------------------------  ← yum情報

 Packages Installed:  ← パッケージのインストール状況
   logwatch.noarch 7.2.1-1.fc5  ← logwatchのインストール

 Packages Erased:  ← パッケージのアンインストール状況
   logwatch  ← logwatchのアンインストール

 ---------------------- yum End -------------------------

 --------------------- Disk Space Begin ------------------------   ← Disk Space情報

 Filesystem                      Size Used Avail Use% Mounted on   ← ディスクスペースの使用状況
 /dev/hda1                        96M  15M   76M  16% /boot
 /dev/mapper/VolGroup00-LogVol00  13G 1.3G   11G  12% /

 ---------------------- Disk Space End -------------------------

 ###################### Logwatch End #########################

 
   
  上記のレポートは一例です。サーバーの使用状況によって様々なログが送られてきます。

上記の他には cron  kernel  qmail  と言ったものが送られてきます。

   
   
ログ収集時間の確認
   
  LogWatch のインストール時に /etc/cron.daily に cron が作成されます。この cron により毎日決まった時間にログが収集されメールが送られてきます。

また、 cron の設定により毎月、毎週、毎時に実行することも可能です。しかし、毎月や毎週では間隔が長過ぎますし毎時では短か過ぎるので毎日で良いと思います。

では、実際の確認方法です。cron の設定ファイルを開きます。下記のように入力して下さい。赤文字は説明です。青文字が入力文字です。

   
   
 
[root@linux]# vi /etc/crontab    ← 入力

 SHELL=/bin/bash
 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=root
 HOME=/

 # run-parts
 01 * * * * root run-parts /etc/cron.hourly
     ← 毎時の実行時間
 02 4 * * * root run-parts /etc/cron.daily
      ← 毎日の実行時間
 22 4 * * 0 root run-parts /etc/cron.weekly
     ← 毎週の実行時間
 42 4 1 * * root run-parts /etc/cron.monthly
    ← 毎月の実行時間
 
   
  LogWatch の cron は /etc/cron.daily に作成されますので 02 4 * * * に実行されます。これは左より 分・時・日・月・週 となりますので毎日 4:02 に実行されるということです。

この時間を書き換えれば実行時間を変更することは可能ですが /etc/cron.daily にある全ての cron の実行時間が変わってしまいますので注意が必要です。

まァ〜 実際は深夜?早朝?の 4:02 に実行されるのですから普通の人は寝ていますし、一日のなかでサーバーに対するアクセスが一番少ない時間帯なのでこの時間が最も良い時間では・・・・・・・したがって、変更する必要は無いと思います。

   
   

戻る