LoginSignup
41
46

More than 5 years have passed since last update.

【fluentd初心者】td-agentでつまずいた

Last updated at Posted at 2013-11-16

本来なら複数のサーバにたまっているログをtd-agentなどで管理し、fluentdで一カ所にまとめていい感じだよねっていうのが、最近のオシャレなログ管理らしい。

統合ログ管理基盤としてのFluentdを試してみました。

一回のぽんこつアプリエンジニアの僕には何の事だかさっぱりだが、
最近仕事でここら辺いじる機会があったので検証がてら以下を元に導入してみた。
さくらサーバーのVPS環境にfluentdとMongoDBをインストール

しかし一向にログが出ない、何度 $ ls /var/log/fluent と叩いてもログファイルが出てこない
行った何がいけないのだろうかと悩みに悩んだところ、原因は以下だった。

td-agentが起動偽装してる!!

Linuxなんて全然詳しくなくて、apacheの起動にもいちいちコマンド調べている僕には何が起きてるかわからなかったがとりあえず現象は以下。

td-agentの起動
$ /etc/init.d/td-agent start
Starting td-agent:                                         [  OK  ]

参考URLを元にtd-agentを導入しプラグインを入れ、ログが出るか試してみたが一向にでない。
しかし・・・

td-agentの再起動
$ /etc/init.d/td-agent restart
Shutting down td-agent:                                    [失敗]
Starting td-agent:                                         [  OK  ]
td-agentの確認
$ /etc/init.d/td-agent status
td-agent が停止していますが pid ファイルが残っています

再起同時にはシャットダウンが失敗してるけど、起動はできてる?あれ?ということはそもそも起動してなくね?ってことでtd-agentのログを見る事に

td-agentのログ
$ /var/log/td-agent/td-agent.log
~ 省略 ~
013-11-16 14:21:22 +0900 [info]: adding source type="forward"
2013-11-16 14:21:22 +0900 [info]: adding source type="http"
2013-11-16 14:21:22 +0900 [info]: adding source type="debug_agent"
2013-11-16 14:21:22 +0900 [info]: adding source type="tail"
2013-11-16 14:21:22 +0900 [warn]: 'pos_file PATH' parameter is not set to a 'tail' source.
2013-11-16 14:21:22 +0900 [warn]: this parameter is highly recommended to save the position to resume tailing.
2013-11-16 14:21:22 +0900 [info]: adding match pattern="td.*.*" type="tdlog"
2013-11-16 14:21:22 +0900 [info]: adding match pattern="debug.**" type="stdout"
2013-11-16 14:21:22 +0900 [info]: adding match pattern="mongo.**" type="mongo"
2013-11-16 14:21:22 +0900 [info]: adding match pattern="apache.access" type="file"
2013-11-16 14:21:22 +0900 [error]: unexpected error error_class=Mongo::ConnectionFailure error=#<Mongo::ConnectionFailure: Expected response 1 but got 1852141647>
  2013-11-16 14:21:22 +0900 [error]: /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/mongo-1.8.6/lib/mongo/networking.rb:167:in `receive_header'
~ 省略 ~

なんかエラー出てた。教えてくれよtd-agentちゃん・・・
ということで改めてFluentdを入れて、td-agent.confを以下のように変更

td-agent.conf
<source>
  type tail
  format apache
  pos_file /var/lib/fluent/access.pos
  path /var/log/httpd/access_log
  tag mongo.apache
</source>

<match mongo.**>
  type mongo

  database apache
  collection access

  host localhost
  port 27017

  flush_interval 10s
</match>

pos_file /var/lib/fluent/access.pos
というのがあるがこれはtd-agent側で用意してくれない一時ファイルなので自分で作って
chmod 777 あたりでいじれるようにする。これで出来た。

なのでtd-agentが動いたように見せかけてくる時は、statusで起動してるのか確認して
td-agent.logを見て、fluentを入れて起動するか確認して、td-agent.confを書き直して、
td-agent.confで使うファイル・ディレクトリの権限が正しいか確認するといい

現象としてはけっこうあるらしく以下でも紹介されている。
【CentOS】Fluentd (td-agent) で 「td-agent が停止していますが pid ファイルが残っています」のエラー
こっちはポートが使われている的な話。

41
46
4

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
41
46