直接 http://www.balabit.com/downloads/syslog-ng/ からソースを持ってきてインストールもOKですが、
せっかくなので /stand/sysinstall で、以下のパッケージをインストールします。
- syslog-ng-1.6.0.r3
- libol-0.3.10
反映させる。
eden# rehash
syslog-ng は、ここにインストールされます。
eden# which syslog-ng
/usr/local/sbin/syslog-ng
eden#
設定ファイルのサンプルはここで、
eden# ls -la /usr/local/etc/syslog-ng/
total 10
drwxr-xr-x 2 root wheel 512 Jun 11 23:54 .
drwxr-xr-x 5 root wheel 512 Jun 11 23:54 ..
-r--r--r-- 1 root wheel 4791 May 26 2003 syslog-ng.conf.sample
eden#
起動スクリプトのサンプルはここ。
eden# ls -la /usr/local/etc/rc.d/
total 6
drwxr-xr-x 2 root wheel 512 Jun 11 23:54 .
drwxr-xr-x 5 root wheel 512 Jun 11 23:54 ..
-r-xr-xr-x 1 root wheel 369 May 26 2003 syslog-ng.sh.sample
eden#
これまでの syslog.conf は以下のようになっていました。
FreeBSD 5.1のインストール直後の内容です。
eden# cat /etc/syslog.conf
# $FreeBSD: src/etc/syslog.conf,v 1.26 2003/04/23 13:08:31 des Exp $
#
# Spaces ARE valid field separators in this file. However,
# other *nix-like systems still insist on using tabs as field
# separators. If you are sharing this file between systems, you
# may want to use only tabs as field separators here.
# Consult the syslog.conf(5) manpage.
*.err;kern.debug;auth.notice;mail.crit /dev/console
*.notice;authpriv.none;kern.debug;lpr.info;mail.crit;news.err /var/log/messages
security.* /var/log/security
auth.info;authpriv.info /var/log/auth.log
mail.info /var/log/maillog
lpr.info /var/log/lpd-errs
ftp.info /var/log/xferlog
cron.* /var/log/cron
*.=debug /var/log/debug.log
*.emerg *
# uncomment this to log all writes to /dev/console to /var/log/console.log
#console.info /var/log/console.log
# uncomment this to enable logging of all log messages to /var/log/all.log
# touch /var/log/all.log and chmod it to mode 600 before it will work
#*.* /var/log/all.log
# uncomment this to enable logging to a remote loghost named loghost
#*.* @loghost
# uncomment these if you're running inn
# news.crit /var/log/news/news.crit
# news.err /var/log/news/news.err
# news.notice /var/log/news/news.notice
!startslip
*.* /var/log/slip.log
!ppp
*.* /var/log/ppp.log
eden#
/stand/sysinstall でインストールした syslog-ng.conf のサンプルは、このようになっています。
FreeBSD用に設定されているのでラッキー。
eden# cat /usr/local/etc/syslog-ng/syslog-ng.conf.sample
#
# This sample configuration file is essentially equilivent to the stock
# FreeBSD /etc/syslog.conf file.
#
#
# options
#
options { long_hostnames(off); sync(0); };
#
# sources
#
source src { unix-dgram("/var/run/log"); udp(); internal(); file("/dev/klog"); };
#
# destinations
#
destination messages { file("/var/log/messages"); };
destination security { file("/var/log/security"); };
destination maillog { file("/var/log/maillog"); };
destination lpd-errs { file("/var/log/lpd-errs"); };
destination cron { file("/var/log/cron"); };
destination consolelog { file("/var/log/console.log"); };
destination all { file("/var/log/all.log"); };
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 slip { file("/var/log/slip.log"); };
destination ppp { file("/var/log/ppp.log"); };
destination console { file("/dev/console"); };
destination allusers { usertty("*"); };
#destination loghost { udp("loghost" port(514)); };
#
# log facility filters
#
filter f_auth { facility(auth); };
filter f_authpriv { facility(authpriv); };
filter f_console { facility(console); };
filter f_cron { facility(cron); };
filter f_daemon { facility(daemon); };
filter f_ftp { facility(ftp); };
filter f_kern { facility(kern); };
filter f_lpr { facility(lpr); };
filter f_mail { facility(mail); };
filter f_news { facility(news); };
filter f_security { facility(security); };
filter f_user { facility(user); };
filter f_uucp { facility(uucp); };
filter f_local0 { facility(local0); };
filter f_local1 { facility(local1); };
filter f_local2 { facility(local2); };
filter f_local3 { facility(local3); };
filter f_local4 { facility(local4); };
filter f_local5 { facility(local5); };
filter f_local6 { facility(local6); };
filter f_local7 { facility(local7); };
#
# log level filters
#
filter f_emerg { level(emerg); };
filter f_alert { level(alert..emerg); };
filter f_crit { level(crit..emerg); };
filter f_err { level(err..emerg); };
filter f_warning { level(warning..emerg); };
filter f_notice { level(notice..emerg); };
filter f_info { level(info..emerg); };
filter f_debug { level(debug..emerg); };
#
# program filters
#
filter f_ppp { program("ppp"); };
filter f_slip { program("startslip"); };
#
# *.err;kern.debug;auth.notice;mail.crit /dev/console
#
log { source(src); filter(f_err); destination(console); };
log { source(src); filter(f_kern); filter(f_debug); destination(console); };
log { source(src); filter(f_auth); filter(f_notice); destination(console); };
log { source(src); filter(f_mail); filter(f_crit); destination(console); };
#
# *.notice;kern.debug;lpr.info;mail.crit;news.err /var/log/messages
#
log { source(src); filter(f_notice); destination(messages); };
log { source(src); filter(f_kern); filter(f_debug); destination(messages); };
log { source(src); filter(f_lpr); filter(f_info); destination(messages); };
log { source(src); filter(f_mail); filter(f_crit); destination(messages); };
log { source(src); filter(f_news); filter(f_err); destination(messages); };
#
# security.* /var/log/security
#
log { source(src); filter(f_security); destination(security); };
#
# mail.info /var/log/maillog
#
log { source(src); filter(f_mail); filter(f_info); destination(maillog); };
#
# lpr.info /var/log/lpd-errs
#
log { source(src); filter(f_lpr); filter(f_info); destination(lpd-errs); };
#
# cron.* /var/log/cron
#
log { source(src); filter(f_cron); destination(cron); };
#
# *.emerg *
#
log { source(src); filter(f_emerg); destination(allusers); };
#
# uncomment this to log all writes to /dev/console to /var/log/console.log
# console.info /var/log/console.log
#
#log { source(src); filter(f_console); filter(f_info); destination(consolelog); };
#
# uncomment this to enable logging of all log messages to /var/log/all.log
# touch /var/log/all.log and chmod it to mode 600 before it will work
# *.* /var/log/all.log
#
#log { source(src); destination(all); };
#
# uncomment this to enable logging to a remote loghost named loghost
# *.* @loghost
#
#log { source(src); destination(loghost); };
#
# uncomment these if you're running inn
# news.crit /var/log/news/news.crit
# news.err /var/log/news/news.err
# news.notice /var/log/news/news.notice
#
#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); };
#
# !startslip
# *.* /var/log/slip.log
#
log { source(src); filter(f_slip); destination(slip); };
#
# !ppp
# *.* /var/log/ppp.log
#
log { source(src); filter(f_ppp); destination(ppp); };
正式ファイル名にリネームします。
eden# cp /usr/local/etc/syslog-ng/syslog-ng.conf.sample /usr/local/etc/syslog-ng/syslog-ng.conf
eden#
syslog-ng のヘルプはこんな感じ。
eden# /usr/local/sbin/syslog-ng -h
Usage: syslog-ng [options]
Accept and manage system log messages
Options:
-s, --syntax-only Only read and parse config file
-d, --debug Turn on debugging messages
-v, --verbose Be a bit more verbose
-F, --foreground Don't fork into background
-f <fname>, --cfgfile=<fname> Set config file name, default=/usr/local/etc/syslog-ng/
syslog-ng.conf
-V, --version Display version number (syslog-ng 1.6.0rc3)
-p <fname>, --pidfile=<fname> Set pid file name, default=/var/run/syslog.pid
-C <dir>, --chroot=<dir> Chroot to directory
-u <user>, --user=<user> Switch to user
-g <group>, --group=<group> Switch to group
eden#
設定ファイル(syslog-ng.conf)の正当性をチェックします。当然大丈夫。
eden# /usr/local/sbin/syslog-ng -s
eden#
次回システム起動時に syslog-ng が起動するようにします。
eden# cp /usr/local/etc/rc.d/syslog-ng.sh.sample /usr/local/etc/rc.d/syslog-ng.sh
eden#
そのかわりに、これまでの syslog を起動しないようにします。/etc/rc.conf を開いて、以下の行を追加します。
syslogd_enable="NO"
syslog-ng を起動するには、最初に syslog を停止させる必要があります。
eden# kill -9 `cat /var/run/syslog.pid `
eden#
syslog-ng を起動。
eden# /usr/local/etc/rc.d/syslog-ng.sh start
Changing permissions on special file /dev/klog
syslog-ngeden#
eden#
動作を確認。
eden# ps -ax | grep syslog
602 ?? Is 0:00.01 /usr/local/sbin/syslog-ng
eden#
ログの出力状態を確認。
eden# tail -n 1 /var/log/messages
Jun 12 00:05:09 eden syslog-ng[602]: syslog-ng version 1.6.0rc3 starting
eden#
大丈夫みたい。
logger でログを出してみましょう。
eden# logger -p local0.notice "hogehoge"
eden# tail -n 1 /var/log/messages
Jun 12 00:06:43 eden kenz: hogehoge
eden#
大丈夫みたい。
system を再起動させます。
再起動したら、プロセスを確認してみましょう。
eden# ps -ax | grep syslog
392 ?? Ss 0:00.02 /usr/local/sbin/syslog-ng
eden#
syslog-ng が動いていて、syslog が起動していないことを確認。
ログのローテーションを確認してみましょう。
現在、このぐらいのログがあるので、
eden# ls -la /var/log/messages
-rw------- 1 root wheel 16730 Jun 12 00:09 /var/log/messages
eden#
/etc/newsyslog を開いて、/var/log/messages がローテーションするサイズに変更します。
eden# cat /etc/newsyslog.conf | grep /var/log/messages
#/var/log/messages 644 5 100 * J
/var/log/messages 644 5 10 * J
eden#
で、newsyslog でローテーションさせます。
eden# newsyslog
ローテーションされているか確認。
eden# ls -la /var/log/messages*
-rw------- 1 root wheel 282 Jun 12 00:14 /var/log/messages
-rw------- 1 root wheel 3069 Jun 12 00:14 /var/log/messages.0.bz2
eden#
されてる、されてる。
では、ログを出してみよう。
eden# logger -p local0.notice "12345"
eden# tail -n 1 /var/log/messages
Jun 12 00:16:17 eden kenz: 12345
eden#
大丈夫だね。