Syslogdでルーターのログを取り、
Webで参照する実験Modified: 24 July 2004
まず、YAMAHAの「RTX1000」のログをLinuxのサーバで受信、記録します。そして、その内容は、いつでも遠隔地からブラウザで確認できるようにするという実験です。
ルータを設定する
"/etc/syslogd.conf" を設定する
syslogdを再起動する
Syslogdの小技
FedraCore1 では、デフォルトで、syslogdとcrondの動作で、一週間ごとにログをローテート(世代管理される)切り替えるように設定されていて、動作しています。
"/etc/logrotate.conf"の設定
# see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # 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 wtmp -- we'll rotate them here /var/log/wtmp { monthly create 0664 root utmp rotate 1 } # system-specific logs may be also be configured here.ルーターのログファイルをローテート対象とするためには、そのログファイルの名称を登録する必要があります。
設定ファイルは、"/etc/logrotate.d/syslog" です。
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron { sharedscripts postrotate /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true endscript }上記を、以下のように追加します。
/var/log/messages /var/log/secure /var/log/maillog /var/log/spooler /var/log/boot.log /var/log/cron /var/www/html/rtx1000/rtx1000-log { sharedscripts postrotate /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true endscript }
定期的実行
FedraCore1では、なにも設定しなくても定期的に実行されるようになっていますので、確認のみ行います。
毎日、"/etc/cron.daily/roglotate" が実行されます。
#!/bin/sh /usr/sbin/logrotate /etc/logrotate.conf EXITVALUE=$? if [ $EXITVALUE != 0 ]; then /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]" fi exit 0
ログが肥大化してきたら、切り替える必要があります。単にリネームしただけでは、切替できません。
まず、現在のログを、”mv”コマンドでリネームします。
# mv router.log router-200102.log 新しい、サイズ0のファイル、を作ります。
# touch router.log デーモンを再起動します。
# /etc/rc.d/init.d/syslog restart 以上で、OKです。
ルータがログを出力するように設定します。
出力するホストを指定
# syslog host 192.168.0.6
ファシリティを指定します
要は、ログの種別です。受け取ったとき、専用のファイルに保存するために指定します。
# syslog facility user
ログの対象を指定します
# syslog notice on
# syslog info on
# syslog debug off
DNSの参照により、IPアドレスでなくURLで記録する
# dns syslog resolv on
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
# Log all the mail messages in one place.
mail.* /var/log/maillog
# Log cron stuff
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg *
# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler
# Save boot messages also to boot.log
local7.* /var/log/boot.log
# RTX1000
user.debug;user.notice;user.info /var/www/html/rtx1000/rtx1000-log
htmlファイルを置いているホームデレクトリに書き込みます。
サイズ0のファイルを作っておきます。
# mkdir /var/www/html/rtx1000
# touch /var/www/html/rtx1000/rtx1000-log
再起動しても有効にするためには、以下のように "syslogd" に、"-r"オプションをつけて起動できるようにします。
: start() { echo -n $"Starting system logger: " daemon syslogd -r $SYSLOGD_OPTIONS RETVAL=$? echo echo -n $"Starting kernel logger: " daemon klogd $KLOGD_OPTIONS echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/syslog return $RETVAL :以下のコマンドで再起動します。
# /etc/init.d/syslog restart カーネルロガーを停止中: [ OK ] システムロガーを停止中: [ OK ] システムロガーを起動中: [ OK ] カーネルロガーを起動中: [ OK ] #