1. 設定ファイル
どういう種類の log がとられているかは /etc/syslog.conf で設定されている.
それらの log は /etc/cron.daily/sysklogd 及び /etc/cron.weekly/sysklogd
で log を定期的に分割、圧縮して一定期間保存するように設定されている.
2. 設定
2.1 /etc/cron.daily/sysklogd
$ vi /etc/cron.daily/sysklogd 
以下の log を保存する期間(日数)をデフォルトの
7 から
90 に変更する.
ここで保存の対象になっている log は
$ syslogd-listfiles 
で表示される /var/log/syslog だけである.
#! /bin/sh
# sysklogd Cron script to rotate system log files daily.
#
# If you want to rotate other logfiles daily, edit
# this script. An easy way is to add files manually,
# to add -a (for all log files) to syslogd-listfiles and
# add some grep stuff, or use the -s pattern argument to
# specify files that must not be listed.
#
# This is a configration file. You are invited to edit
# it and maintain it on your own. You'll have to do
# that if you don't like the default policy
# wrt. rotating logfiles (i.e. with large logfiles
# weekly and daily rotation may interfere). If you edit
# this file and don't let dpkg upgrade it, you have full
# control over it. Please read the manpage to
# syslogd-listfiles.
#
# Written by Martin Schulze .
# $Id: cron.daily,v 1.14 2007-05-28 16:33:34 joey Exp $
test -x /usr/sbin/syslogd-listfiles || exit 0
test -x /sbin/syslogd || exit 0
test -f /usr/share/sysklogd/dummy || exit 0
set -e
cd /var/log
logs=$(syslogd-listfiles --ignore-size)
test -n "$logs" || exit 0
for LOG in $logs
do
if [ -s $LOG ]; then
savelog -g adm -m 640 -u root -c 90 $LOG >/dev/null
fi
done
# Restart syslogd
#
/etc/init.d/sysklogd reload-or-restart > /dev/null
|
2.2 /etc/cron.weekly/sysklogd
$ vi /etc/cron.weekly/sysklogd 
以下の log を保存する期間(週数)をデフォルトの
4 から
12 に変更する.
ここで保存の対象になっている log は以下の通り.
$ syslogd-listfiles --weekly
/var/log/messages
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.info
/var/log/uucp.log
/var/log/lpr.log
/var/log/user.log
/var/log/kern.log
/var/log/auth.log
/var/log/mail.log
/var/log/daemon.log
/var/log/debug |
#! /bin/sh
# sysklogd Cron script to rotate system log files weekly.
#
# If you want to rotate logfiles daily, edit
# this script and /etc/cron.daily/sysklogd to get
# the logfiles in sync (they must not occur in both
# files).
#
# This is a configration file. You are invited to edit
# it and maintain it on your own. You'll have to do
# that if you don't like the default policy
# wrt. rotating logfiles (i.e. with large logfiles
# weekly and daily rotation may interfere). If you edit
# this file and don't let dpkg upgrade it, you have full
# control over it. Please read the manpage to
# syslogd-listfiles.
#
# Written by Ian A. Murdock .
# $Id: cron.weekly,v 1.11 2007-05-28 16:33:34 joey Exp $
test -x /usr/sbin/syslogd-listfiles || exit 0
test -x /sbin/syslogd || exit 0
test -f /usr/share/sysklogd/dummy || exit 0
set -e
cd /var/log
logs=$(syslogd-listfiles --weekly)
test -n "$logs" || exit 0
for LOG in $logs
do
if [ -s $LOG ]; then
savelog -g adm -m 640 -u root -c 12 $LOG >/dev/null
fi
done
# Restart syslogd
#
/etc/init.d/sysklogd reload-or-restart > /dev/null
|
3. 補足
- 上記以外の log に関しては各々のサーバに合わせて設定すること.
- 上の例を見れば syslog も一週間毎に変更することは容易だろう.
- この設定だと /var/log/ 以下に大量の log ファイルがたまることになるが,
/etc/syslog.conf を編集すれば log をディレクトリ毎に分割することができる.