-->

2009-12-16

/etc/logrotate.d/syslog-ngの修正

この記事はsyslog-ngの設定例です。

設定に書かれているファイルのリストを取得します。
grep /var/log/ /etc/syslog-ng/syslog-ng.conf|grep -v ^#|awk -F'"' '{print $2}'|sed 's/\$[A-Za-z_][0-9A-Za-z_]*/\*/g'|sed 's/\*\**/\*/g'|awk 'BEGIN{A=""}{A=A" "$0}END{print "result:"A}'

設定を編集します。
$ diff syslog-ng.2009-12-16 syslog-ng
7c7
< /var/log/messages {
---
> /var/log/HOSTS/*/*.log /var/log/auth.log /var/log/syslog /var/log/cron.log /var/log/daemon.log /var/log/kern.log /var/log/lpr.log /var/log/user.log /var/log/uucp.log /var/log/mail.log /var/log/avc.log /var/log/audit.log /var/log/pax.log /var/log/grsec.log /var/log/mail.info /var/log/mail.warn /var/log/mail.err /var/log/news/news.crit /var/log/news/news.err /var/log/news/news.notice /var/log/debug /var/log/messages {

設定をテストします。
sudo logrotate -dv syslog-ng

ベースとなるファイルの一覧です。
$ equery files syslog-ng |grep -P /usr/share/.*/syslog-ng.conf.*
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.HP-UX.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.RedHat.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.SunOS.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.debian.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.doc.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.gentoo.3.0.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.gentoo.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.gentoo.fbsd.3.0.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.gentoo.fbsd.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.gentoo.hardened.3.0.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.gentoo.hardened.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.sample.bz2
/usr/share/doc/syslog-ng-3.0.4/syslog-ng.conf.solaris.bz2
/usr/share/man/man5/syslog-ng.conf.5.bz2

アップデート時にエラーが出るので@version: 3.0などを修正します。
$ cat /etc/syslog-ng/syslog-ng.conf
@version: 3.0
# Copyright 2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /etc/config-archive/etc/syslog-ng/syslog-ng.conf,v 1.1 2009/11/02 13:09:56 root Exp $

#
# Syslog-ng configuration file, compatible with default hardened installations.
#

options {
        chain_hostnames(off);
        flush_lines(0);
        stats_freq(43200);
};

#options {
#       chain_hostnames(off);
#       sync(0);
#       stats(43200);
#       long_hostnames(off);
#       use_dns(no);
#       create_dirs(yes);
#};

source src {
        unix-stream("/dev/log");
        internal();
#       udp(ip(0.0.0.0) port(514));
};
source kernsrc { file("/proc/kmsg"); };

source net { udp(); };
log { source(net); destination(net_logs); };
destination net_logs { file("/var/log/HOSTS/$HOST/$YEAR$MONTH$DAY.log" create_dirs(yes)); };

destination authlog { file("/var/log/auth.log"); };
destination s_sys { file("/var/log/syslog"); };
destination cron { file("/var/log/cron.log"); };
destination daemon { file("/var/log/daemon.log"); };
destination kern { file("/var/log/kern.log"); file("/dev/tty12"); };
destination lpr { file("/var/log/lpr.log"); };
destination user { file("/var/log/user.log"); };
destination uucp { file("/var/log/uucp.log"); };
#destination ppp { file("/var/log/ppp.log"); };
destination mail { file("/var/log/mail.log"); };

destination avc { file("/var/log/avc.log"); };
destination audit { file("/var/log/audit.log"); };
destination pax { file("/var/log/pax.log"); };
destination grsec { file("/var/log/grsec.log"); };

destination mailinfo { file("/var/log/mail.info"); };
destination mailwarn { file("/var/log/mail.warn"); };
destination mailerr { file("/var/log/mail.err"); };

destination newscrit { file("/var/log/news/news.crit"); };
destination newserr { file("/var/log/news/news.err"); };
destination newsnotice { file("/var/log/news/news.notice"); };

destination debug { file("/var/log/debug"); };
destination messages { file("/var/log/messages"); };
destination console { usertty("root"); };
destination console_all { file("/dev/tty12"); };
#destination loghost { udp("loghost" port(999)); };

destination xconsole { pipe("/dev/xconsole"); };

filter f_auth { facility(auth); };
filter f_authpriv { facility(auth, authpriv); };
filter f_syslog { not facility(authpriv, mail); };
filter f_cron { facility(cron); };
filter f_daemon { facility(daemon); };
filter f_kern { facility(kern); };
filter f_lpr { facility(lpr); };
filter f_mail { facility(mail); };
filter f_user { facility(user); };
filter f_uucp { facility(uucp); };
#filter f_ppp { facility(ppp); };
filter f_news { facility(news); };
filter f_debug { not facility(auth, authpriv, news, mail); };
filter f_messages { level(info..warn)
        and not facility(auth, authpriv, mail, news); };
filter f_emergency { level(emerg); };

filter f_info { level(info); };

filter f_notice { level(notice); };
filter f_warn { level(warn); };
filter f_crit { level(crit); };
filter f_err { level(err); };

filter f_avc { match(".*avc: .*" value("MESSAGE")); };
filter f_audit { match("^audit.*" value("MESSAGE")) and not match(".*avc: .*" value("MESSAGE")); };
filter f_pax { match("^PAX:.*" value("MESSAGE")); };
filter f_grsec { match("^grsec:.*" value("MESSAGE")); };

log { source(src); filter(f_authpriv); destination(authlog); };
log { source(src); filter(f_syslog); destination(s_sys); };
log { source(src); filter(f_cron); destination(cron); };
log { source(src); filter(f_daemon); destination(daemon); };
log { source(kernsrc); filter(f_kern); destination(kern); };
log { source(src); filter(f_lpr); destination(lpr); };
log { source(src); filter(f_mail); destination(mail); };
log { source(src); filter(f_user); destination(user); };
log { source(src); filter(f_uucp); destination(uucp); };
log { source(kernsrc); filter(f_pax); destination(pax); };
log { source(kernsrc); filter(f_grsec); destination(grsec); };
log { source(kernsrc); filter(f_audit); destination(audit); };
log { source(kernsrc); filter(f_avc); destination(avc); };
log { source(src); filter(f_mail); filter(f_info); destination(mailinfo); };
log { source(src); filter(f_mail); filter(f_warn); destination(mailwarn); };
log { source(src); filter(f_mail); filter(f_err); destination(mailerr); };
log { source(src); filter(f_news); filter(f_crit); destination(newscrit); };
log { source(src); filter(f_news); filter(f_err); destination(newserr); };
log { source(src); filter(f_news); filter(f_notice); destination(newsnotice); };
log { source(src); filter(f_debug); destination(debug); };
log { source(src); filter(f_messages); destination(messages); };
log { source(src); filter(f_emergency); destination(console); };
#log { source(src); filter(f_ppp); destination(ppp); };
log { source(src); destination(console_all); };

0 件のコメント: