Last-modified: 2014-08-11 (月) 05:20:13
rsyslog/ログ格納にDBを指定したい

概要

ログ格納にDBを指定する方法です。

手順

  1. rsyslog-mysqlをインストールします。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    apt-get install rsyslog-mysql
  2. /etc/rsyslog.d/mysql.confを編集します。
    転送するログを変更する場合は、/etc/rsyslog.confと同じようにファシリティ、プライオリティを設定します。
    Everything is expanded.Everything is shortened.
      1
      2
      3
    
     
    -
    !
    
    $ModLoad ommysql
    # [ファシリティ].[プライオリティ] :[MySQLサーバのアドレス],[データベース名],[ユーザー名],[パスワード]
    *.notice :ommysql:localhost,Syslog,rsyslog,AAAAA
  3. rsyslogを再起動します。
    Everything is expanded.Everything is shortened.
      1
    
     
    
    /etc/init.d/rsyslog restart

補足

  1. SystemEventsテーブルにそのままアクセスしても、不要な行ばかりで見にくいです。
    以下のようなビューを作成したほうが便利かと思います。
    Everything is expanded.Everything is shortened.
      1
      2
      3
      4
    
     
     
     
     
    
    CREATE VIEW `Syslog`.`rsyslog` AS
      SELECT DeviceReportedTime,Priority,FromHost,SysLogTag,Message
      FROM SystemEvents
      ORDER BY DeviceReportedTime;

検証時の環境