CentOS6にlogwatchを導入する

logwatch 開発ツール

logwatch

さくらVPSがそうなのか、CentOSの仕様なのか…
CentOS5系では標準で入っていたlogwatchがCentOS6には入っていないようなので入れてみました

インストール

~~~
sudo yum install logwatch
~~~

動作確認

~~~
$ sudo logwatch –print

################### Logwatch 7.3.6 (05/19/07) ####################
Processing Initiated: Mon Apr 9 10:04:43 2012
Date Range Processed: yesterday
( 2012-Apr-08 )
Period is day.
Detail Level of Output: 0
Type of Output: unformatted

以下略
~~~

メールの宛先を変える場合

デフォルトではrootへメールが飛ぶので違う宛先にしたい場合は設定ファイルを編集します

~~~
sudo vim /usr/share/logwatch/default.conf/logwatch.conf

MailTo = root # ここを好きなアドレスに変更
~~~

httpのログを省略されたくないとき

デフォルトだと↓のような感じで省略されちゃって、どこのアドレスなんだか分からないですよね
~~~
Requests with error response codes
400 Bad Request
/wp-content/plugins/ktai-style/inc/redir.p … once=ce3e3c8380: 1 Time(s)
~~~

sudo vim /usr/share/logwatch/scripts/services/http
~~~
if ( ($field{http_rc} >= 400) &&
!((defined $ignoreURLs) && ($field{url} =~ /$ignoreURLs/)) &&
!((defined $ignoreIPs) && ($field{client_ip} =~ /$ignoreIPs/)) ) {
my $fmt_url = $field{url};
if (length($field{url}) > 60) { #ここで省略をしているっぽいので60を適当な数字に変更する
$fmt_url = substr($field{url},0,42) . ” … ” .
substr($field{url},-15,15);
}
$needs_exam{$field{http_rc}}{$fmt_url}++;
}
~~~
60を400にしてみたところ、省略されずに表示されました。

httpのログをサービス(access.log)毎に分けたい

こうしないと、ブログと他のサービスが混じっちゃって分かりにくい…
けどやり方がわかりません \(^o^)/

PHPのerror_logも監視したい

~~~
$ vim /usr/share/logwatch/default.conf/logfiles/php.conf

LogFile = httpd/php_log
LogFile = httpd/*error_log

# adjust your php.ini accordingly:
# error_log = /var/log/httpd/php_log
# log_errors = On

# 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 = httpd/php_log.*
Archive = httpd/php_log-*
Archive = httpd/*error_log-*
~~~

参考:http://mbaierl.com/2009/03/logwatch-for-php-errors-the-apache-error-log-and-mysql.html

とあるけど、printしてもエラーが出てこない
何が原因でしょうね。。

とりあえず

1日2個メールが飛んで来ちゃうけど、導入はひとまず終了です

コメント

タイトルとURLをコピーしました