Fluentdの動作テストを行ったメモ

Fluentdを使ってログ集約設定を試してみました。


apacheのアクセスログなどを集約して動作確認するのが普通なのかもしれませんが、
まずはクライアントとサーバー間でログが自分の環境でちゃんと送られるのか確認したかったので、
ログファイルに1行書かれるデータを集約する簡単な動作確認用の設定を行ってみました。

やりたいこと

クライアントのログファイル

/tmp/testlog.log


1行ログを書く。

echo "hogehoge" >> /tmp/testlog.log

こんな感じです。


そのログが
サーバーのログファイル

/tmp/client.example.com-testlog.log

に送られ、書き込まれるかどうか。



結果は無事出来ました。というか、最初から単純なログファイルで動作確認しなくても、apacheのログとかもろもろがすぐに集約出来るほど設定が簡単でした!
プラグインたくさん公開されていてすごい!


まずは環境紹介

クライアント(ログを送る側)
ホスト名 OS td-agent ログファイル名(こいつの中身を送る)
client.example.com CentOS 5.8 td-agent-1.1.7-0 /tmp/testlog.log


サーバー(ログを受取る側)
ホスト名 OS td-agent ログファイル名(送られて来たログを書きこむ)
server.example.com CentOS 5.8 td-agent-1.1.7-0 /tmp/client.example.com-testlog.log


インストール(クライアント、サーバー共通)

http://help.treasure-data.com/kb/installing-td-agent-daemon/installing-td-agent-for-redhat-and-centos

/etc/yum.repos.d/td.repo
[treasuredata]
name=TreasureData
baseurl=http://packages.treasure-data.com/redhat/$basearch
gpgcheck=0
↑の設定後、yumでインストール
yum install td-agent.x86_64


クライアント設定(ログを送る側)

/etc/td-agent/td-agent.conf
<source>
type tail
format /^(?<taillog>.*)$/
path /tmp/testlog.log
tag hoge
</source>

<match hoge>
type tcp
host server.example.com
port 24224
buffer_type file
buffer_path /tmp/testlog-tmp.log
flush_interval 10s
</match>


設定後td-agentデーモン再起動
/etc/init.d/td-agent restart


サーバー設定(ログを受取る側)

/etc/td-agent/td-agent.conf
<source>
type tcp
port 24224
</source>

<match hoge>
type file
path /tmp/client.example.com-testlog.log
</match>


設定後td-agentデーモン再起動
/etc/init.d/td-agent restart


結果

クライアント側でログを書きこんでみる。
echo "hogehoge" >> /tmp/testlog.log


サーバー側でログ出力結果を確認する。

/tmp/client.example.com-testlog.log.20120719.b4c517ef01b49f153
こういったファイル名でログファイルが生成され、以下のようなログが書き込まれました。

2012-07-19T00:00:01	hoge		{"taillog":"hogehoge"}

動作確認が出来たので、今後は色んなログ集約の設定をやってみようと思います。