Tips記事
» 2000年11月08日 00時00分 UPDATE

システムログが1週間でクリアされてしまう

[ITmedia]

 Red Hat系ディストリビューションの一部では,システムログが肥大化して1つのファイルが大容量にならないように,定期的に古いログに拡張子が付けられて整理される。「ログを回す」などと表現される作業だ。

# ls /var/log/httpd/
access_log access_log.3 access_log.6 error_log.2 error_log.5
access_log.1 access_log.4 error_log error_log.3 error_log.6
access_log.2 access_log.5 error_log.1 error_log.4

 しかし,ログ管理ツールなどを利用している場合には,週ごとにクリアされては都合の悪いことがある。そこで,ここでは週ごとから月ごとに変更する手順を紹介しよう。

 週ごとのログ整理設定を行っているのは,/etc/logrotate.confファイルである。ファイルの中身は次のようになっており,システムで記録されるログをどのように管理するかが記述されている。

# vi /etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
monthly       ←このように変更する

# keep 4 weeks worth of backlogs
rotate 50
mail root

# send errors to root
errors root

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own lastlog or wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
create 0664 root utmp
rotate 1
}

# system-specific logs may be configured here

 上記のように「monthly」へ変更すると,その単語の通り,月ごとのログファイル更新に切り替わる。

 この設定例はすべてのログについて有効となるが,httpサービスだけに設定したい場合には,/etc/logrotate.d/ディレクトリ下にあるそれぞれのサービス名のファイルを編集すればよい。

# ls -l /etc/logrotate.d/
total 44
-rw-r--r-- 1 root root 494 Mar 2 2000 apache
-rw-r--r-- 1 root root 122 Feb 4 2000 cron
-rw-r--r-- 1 root root  78 Jun 23 22:18 ftpd
-rw-r--r-- 1 root root 145 Mar 7 2000 linuxconf
-rw-r--r-- 1 root root 168 Sep 8 04:37 mgetty
-rw-r--r-- 1 root root 102 Feb 29 2000 named
-rw-r--r-- 1 root root 169 Sep 16 14:26 samba
-rw-r--r-- 1 root root  49 Sep 8 04:37 sendfax
-rw-r--r-- 1 root root 543 Feb 15 2000 squid
-rw-r--r-- 1 root root 410 Feb 4 2000 syslog
-rw-r--r-- 1 root root 544 Mar 7 2000 uucp

Copyright © ITmedia, Inc. All Rights Reserved.

注目のテーマ