fluentdの簡単な使い方、設定方法一覧

fluentdを使ってみたメモ。

簡単な動かし方、設定ファイルの書き方一覧を書いています。


maptail

画像はfluentd公式ページより引用



fluentdはログの転送・集約を簡単に行うためのツール


fluentd




Scribe使

fluentd

fluentd使

fluentfluentd

fluentd


fluentd



GemRPM使yum使

fluentd Installation


Gem使


$ gem install fluentd --no-ri --no-rdoc

# カレントディレクトリに設定ファイルを作ります
$ fluentd --setup ./fluent

# fluentdの実行。デーモン起動オプションもあります
$ fluentd -c ./fluent/fluent.conf -vv &








3

fluentd Installation


# sourceディレクティブ。入力方法を決める
<source>
  type forward
</source>



# matchディレクティブ。マッチした入力への処理を決める
<match index.html>
  type file
  path /var/log/fluent/access1
</match>



# includeディレクティブ。複数のconfファイルをインクルードする時に使う
# http経由の指定も可能
include config.d/*.conf
include http://example.com/fluent.conf



source

使HTTP

match

使fluent

include

/etc/log/httpd/conf.d/*.conf

tag()

IDmatchdebug.testfluentdFAQ


fluentd



Gem


# fluentdの実行。デーモン起動オプションもあります
$ fluentd -c ./fluent/fluent.conf -vv &

# jobsで番号を調べてから
kill % [job id]



RPM/etc/init.d/


$ /etc/init.d/td-agent start
$ /etc/init.d/td-agent stop
$ /etc/init.d/td-agent restart
$ /etc/init.d/td-agent status





match



matchdebug.**debug.aaa

match使

fluentd Installation

# 設定ファイルの中身はこれだけ
<source>
  type forward
</source>
<match debug.**>
  type stdout
</match>



# 設定ファイルを指定して起動
$ fluentd -c ./fluent/fluent.conf -vv &

# 標準出力に結果が表示されます
$ echo '{"json":"message dayo"}' | fluent-cat debug.test




<source>
  type forward
</source>
<match apache.access>
  type file
  path /var/log/fluent/access
</match>



# 設定ファイルを指定して起動
$ fluentd -c ./fluent/fluent.conf -vv &

# 指定したファイルに結果が表示されます
$ echo '{"json":"message dayo"}' | fluent-cat apache.access




<source>
  type tail
  format apache
  path /var/log/httpd-access.log
  tag apache.access
</source>
<match apache.access>
  type file
  path /var/log/fluent/access
</match>



# 設定ファイルを指定して起動
$ fluentd -c ./fluent/fluent.conf -vv &

# アクセスログ経由で、指定したファイルに結果が表示されます
$ curl http://localhost/index.html -F 'json={"log":"test_dayo"}'



HTTP

8888fluentdListen8888使

# http://localhost:8888/<tag>?json=<json>
<source>
  type http
  port 8888
</source>
<match index.html>
  type file
  path /var/log/fluent/access
</match>



# 設定ファイルを指定して起動
$ fluentd -c ./fluent/fluent.conf -vv &

# 指定したファイルに結果が表示されます。この場合はindex.htmlタグにひっかかる
$ curl http://localhost:8888/index.html -F 'json={"log":"test_dayo"}'

# この場合はaaa.index.htmlタグにひっかかる
$ curl http://localhost:8888/aaa/index.html -F 'json={"log":"test_dayo"}'





fluentd



Fluentd High Availability Configuration

# ログ転送側fluentdの設定ファイル
<match mytag.**>
  type forward

  # primary host
  <server>
    host 192.168.0.1
    port 24224
  </server>
  # use secondary host
  <server>
    host 192.168.0.2
    port 24224
    standby
  </server>

  # use longer flush_interval to reduce CPU usage.
  # note that this is a trade-off against latency.
  flush_interval 60s
</match>



# ログ受け取り側fluentdの設定ファイル
# Input
<source>
  type forward
  port 24224
</source>

# Output
<match mytag.**>
  ...
</match>




<match myapp.**>
  type copy

  # 標準出力
  <store>
    type stdout
  </store>

  # ファイル
  <store>
    type file
    path /var/log/fluent/myapp
  </store>

  # 他のfluentdサーバーへ転送
  <store>
    type forward
    host 192.168.0.13
    buffer_type file
    buffer_path /var/log/fluent/myapp-forward
    retry_limit 50
    flush_interval 10s
  </store>
</match>




# fluentの内部イベントログを出力
<match fluent.**>
  type null
</match>



マッチしなかったログを指定ファイルへ保存。ついでに圧縮
<match **>
  type file
  path /var/log/fluent/else
  compress gz
</match>








mongoDBHDFL






著者プロフィール
Webサイトをいくつか作っています。

著者プロフィール

ツイッターはこちら