接收linux syslog

Linux的syslog是常用系統資訊蒐集的工具,蒐集在本機常常沒辦法提供很及時的支援,這時候如果透過一台fluentd來蒐集,則可以達到比較完整的紀錄功能...

在fluentd上,設定syslog的收集可以透過官方所內建的syslog模組,為了避免傳送協定上的差異,我們可以直接開起udp + tcp兩種協定,避免漏掉傳送過來的log。

設定檔

完整的設定如下:

#syslog.conf
<source>
  type syslog
  protocol_type udp
  port 514
  bind 0.0.0.0
  tag system
</source>
<source>
  type syslog
  protocol_type tcp
  port 514
  bind 0.0.0.0
  tag system
</source>

<match system.**>
  type copy
  <store>
    type stdout
  </store>
</match>

測試

執行這個設定:

$ td-agent -c syslog.conf

如果一切無誤,可以收到下面的log

...(skip)
2015-06-11 11:45:03 +0000 system.authpriv.info: {"host":"simon-centos6","ident":"su","message":"pam_unix(su-l:session): session closed for user root"}
2015-06-11 11:45:03 +0000 system.authpriv.notice: {"host":"simon-centos6","ident":"sudo","message":"simonsu_mitac_com_tw : TTY=pts/0 ; PWD=/home/simonsu_mitac_com_tw ; USER=root ; COMMAND=/bin/su -"}
2015-06-11 11:45:03 +0000 system.authpriv.info: {"host":"simon-centos6","ident":"su","message":"pam_unix(su-l:session): session opened for user root by simonsu_mitac_com_tw(uid=0)"}

附註

在傳送端,我們需要打開Linux上的rsyslog的設定...

$ vi /etc/rsyslog.conf

在設定的最後面加上:

*.* @@remote-host:514

其中remote-host換成log server的位置,啟動之後,就可以將syslog傳到該server的位置。

$ /etc/init.d/rsyslog restart

PS: 不同的linux的設定可能有些許不同,需要稍加修改。

results matching ""

    No results matching ""