LoginSignup
139
135

More than 5 years have passed since last update.

fluentdインストール(丁寧な説明つき)

Last updated at Posted at 2015-02-11

fluentdのインストール方法はたくさんある。

  • RPMパッケージからFluentdをインストールする (Redhat Linux)
  • DEBパッケージからFluentdをインストールする (Debian / Ubuntu Linux)
  • DMGパッケージからFluentdをインストールする (Mac OS X)
  • Ruby GemからFluentdをインストールする
  • ChefでFluentdをインストールする
  • ソースコードからFluentdをインストールする
  • Heroku上にFluentd (td-agent)をインストールする
  • AWS Elastic Beanstalk上にFluentd (td-agent)をインストールする

これらは公式HPにまとめて載っている。

▼公式HP
http://docs.fluentd.org/ja/categories/installation

本ブログでは、「Ruby GemからFluentdをインストールする」方法を解説する。

0. 前提条件

  • Ruby (>= 1.9.3)

1. インストール → 実行

下記のたった4行で、インストールから実行まで出来ます。

gem install fluentd --no-ri --no-rdoc
fluentd --setup ./fluent
fluentd -c ./fluent/fluent.conf -vv &
echo '{"json":"message"}' | fluent-cat debug.test
  • 1行目:インストール
  • 2行目:./fluentに設定ファイル(fluent.conf)を作成
  • 3行目:fluentdの実行
    • ./fluent/fluent.conf:読み込む設定ファイルの指定
    • -vvオプション:トレースモード
    • &:バックグラウンドで実行 → 面倒なので&付けずに実行することも多い
    • バックグラウンドで実行した場合、killコマンドで実行を止める
  • 4行目:正常にfluentdが実行されていることをテスト
    • 2011-07-10 16:49:50 +0900 debug.test: {"json":"message"}のようなメッセージが出れば実行成功
    • fluent-catコマンド:fluentdにtcp経由でログを送ってくれるコマンド

2. おまけ

  • fluentdの仕事
  • 単語の意味
  • 設定ファイルを覗いてみよう

2-1. fluentdの仕事

fluentdは、「ログをどうにかするパイプ役」です。

  • どこからかログを受け取り、どこかへログを出力する
  • 入力源はいくつあっても良い(設定ファイルで指定)
  • 出力先もいくつあっても良い(設定ファイルで指定)

2015_0210fluent.jpg

2-2. 単語の意味

2-2-1. sourceとmatch

設定ファイルにて、入力はsource、出力はmatchで記述。

  • source:ログの入力方法を決める。デフォルトで使えるものは、標準入力、ファイル、ポート指定のHTTP通信等。
  • match:ログの出力方法を指定する。デフォルトで使えるものは、標準出力、ファイル、他のfluentサーバーへの転送等。

2-2-2. tagとvalue

echo '{"json":"message"}' | fluent-cat debug.test
  • value:保存したいもの('{"json":"message"}'がこれにあたる)
  • tag:valueを交通整備するもの(debug.testがこれにあたる)

2-3. 設定ファイルを覗いてみよう

$ cat ~/fluent/fluent.conf

# In v1 configuration, type and id are @ prefix parameters.
# @type and @id are recommended. type and id are still available for backward compatibility

## built-in TCP input
## $ echo <json> | fluent-cat <tag>
<source>
  @type forward
  @id forward_input
</source>

## built-in UNIX socket input
#<source>
#  @type unix
#</source>

# HTTP input
# http://localhost:8888/<tag>?json=<json>
<source>
  @type http
  @id http_input

  port 8888
</source>

## File input
## read apache logs with tag=apache.access
#<source>
#  @type tail
#  format apache
#  path /var/log/httpd-access.log
#  tag apache.access
#</source>

# Listen HTTP for monitoring
# http://localhost:24220/api/plugins
# http://localhost:24220/api/plugins?type=TYPE
# http://localhost:24220/api/plugins?tag=MYTAG
<source>
  @type monitor_agent
  @id monitor_agent_input

  port 24220
</source>

# Listen DRb for debug
<source>
  @type debug_agent
  @id debug_agent_input

  bind 127.0.0.1
  port 24230
</source>

## match tag=apache.access and write to file
#<match apache.access>
#  @type file
#  path /var/log/fluent/access
#</match>

## match tag=debug.** and dump to console
<match debug.**>
  @type stdout
  @id stdout_output
</match>

# match tag=system.** and forward to another fluent server
<match system.**>
  @type forward
  @id forward_output

  <server>
    host xxx.xxx.xxx.xxx
  </server>
  <secondary>
    <server>
      host xxx.xxx.xxx.yyy
    </server>
  </secondary>
</match>

<match dev.action.log>
  @type stdout
  @id stdout_output
</match>

## match tag=myapp.** and forward and write to file
#<match myapp.**>
#  @type copy
#  <store>
#    @type forward
#    buffer_type file
#    buffer_path /var/log/fluent/myapp-forward
#    retry_limit 50
#    flush_interval 10s
#    <server>
#      host xxx.xxx.xxx.zzz
#    </server>
#  </store>
#  <store>
#    @type file
#    path /var/log/fluent/myapp
#  </store>
#</match>

## match fluent's internal events
#<match fluent.**>
#  @type null
#</match>

## match not matched logs and write to file
#<match **>
#  @type file
#  path /var/log/fluent/else
#  compress gz
#</match>
  • このファイルをコピペしないでください
    • このままでは正常に動作しません。
    • 全体理解のため、参考程度にとどめてください。
  • sourceで入力、matchで出力を指定

(参考URL)
▼fluentdの簡単な使い方、設定方法一覧
http://hivecolor.com/id/37

139
135
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
139
135