内容へ移動
ClownWiki
ユーザ用ツール
ログイン
サイト用ツール
検索
ツール
文書の表示
以前のリビジョン
バックリンク
最近の変更
メディアマネージャー
サイトマップ
ログイン
>
最近の変更
メディアマネージャー
サイトマップ
トレース:
fluentd:fluentd-log
この文書は読取専用です。文書のソースを閲覧することは可能ですが、変更はできません。もし変更したい場合は管理者に連絡してください。
====== Fluentdでログ収集 ====== ===== インストール ===== リポジトリ追加 <code> # vi /etc/yum.repos.d/td.repo </code> <code> [treasuredata] name=TreasureData baseurl=http://packages.treasure-data.com/redhat/$basearch gpgcheck=0 </code> インストール <code> # yum -y install td-agent </code> ===== [ローカル]ログファイル ⇒ [ローカル]ログファイル ===== 設定ファイル修正 <code> # cp /etc/td-agent/td-agent.conf /etc/td-agent/td-agent.conf.org # vi /etc/td-agent/td-agent.conf </code> <code> <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_log </match> </code> ログファイル保存場所 <code> # mkdir /var/log/fluent # chown td-agent:td-agent /var/log/fluent </code> パーミッション変更(グループに読取・実行権限付与) <code> # chmod g+rx /var/log/httpd </code> Fluentdスタート <code> # /etc/init.d/td-agent start Starting td-agent: [ OK ] </code> アクセスログ確認 <code> # tail /var/log/fluent/access_log.20130131.b4d49ecf89504b484 2013-01-31T16:28:03-08:00 apache.access {"host":"192.168.26.1","user":"-","method":"GET","path":"/pma/js/jquery/jquery.qtip-1.0.0-rc3.js?ts=1356015781","code":"304","size":"-","referer":"http://192.168.26.143/pma/","agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17"} </code> ===== [ローカル]ログファイル ⇒ [ローカル]MongoDB ===== FluentdのMogoDBプラグインインストール <code> # /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-mongo Fetching: fluent-plugin-mongo-0.6.13.gem (100%) Successfully installed fluent-plugin-mongo-0.6.13 1 gem installed Installing ri documentation for fluent-plugin-mongo-0.6.13... Installing RDoc documentation for fluent-plugin-mongo-0.6.13... </code> 設定ファイル修正 <code> # cp /etc/td-agent/td-agent.conf /etc/td-agent/td-agent.conf.file # vi /etc/td-agent/td-agent.conf </code> <code> <source> type tail format apache path /var/log/httpd/access_log tag mongo.apache </source> <match mongo.**> type mongo # DB名「apache」のコレクション「access」に保存 database apache collection access # MongoDB接続先とポート host localhost port 27017 #インターバル flush_interval 10s </match> </code> Fluentdスタート <code> # /etc/init.d/td-agent restart Shutting down td-agent: [ OK ] Starting td-agent: [ OK ] </code> MongoDBにログが登録されたことを確認 <code> # mongo MongoDB shell version: 2.2.2 connecting to: test > show dbs apache 0.203125GB local (empty) > use apache switched to db apache > show collections access system.indexes > db.access.findOne() { "_id" : ObjectId("510b0daeddfe4129a7000001"), "host" : "192.168.26.1", "user" : "-", "method" : "GET", "path" : "/pma/", "code" : "200", "size" : "6789", "referer" : "-", "agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17", "time" : ISODate("2013-02-01T00:34:50Z") } </code> ===== [リモート]ログファイル ⇒ [ローカル]MongoDB ===== リモート環境にFluentdをインストールして、設定ファイル編集 <code> # vi /etc/td-agent/td-agent.conf <source> type tail format apache path /var/log/httpd/access_log tag mongo.apache </source> <match mongo.apache> type forward <server> host 192.168.26.143 port 24224 </server> flush_interval 10s </match> </code> リモート環境でFluentdスタート <code> # /etc/init.d/td-agent start Starting td-agent: [ OK ] </code> ローカル環境にFluentdをインストールして、設定ファイル編集 <code> # vi /etc/td-agent/td-agent.conf </code> <code> +) <source> +) type forward +) port 24224 +) </source> </code> ローカル環境でFluentdリスタート <code> # /etc/init.d/td-agent restart Shutting down td-agent: [ OK ] Starting td-agent: [ OK ] </code> ===== td-agent.conf -- input部のサンプル ===== 以下のフォーマットの場合のfluentdのformat定義 <code> LogFormat "%h %A %t \"%m %U %H\" %>s %b \"%q\" %{OPENSOCIAL_VIEWER_ID}n \"%{Referer}i\" \"%{User-Agent}i\"" combined </code> <code> <source> type tail format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" (?<received_byte>[^ ]*) (?<sent_byte>[^ ]*) (?<response_time_micro_sec>[^ ]*))?$/ time_format %d/%b/%Y:%H:%M:%S %z path /var/log/httpd/www.example.jp/access_log/access_log pos_file /var/log/td-agent/pos/apache.access.api.pos tag apache.access.api </source> <source> type tail format /^\[[^ ]* (?<time>[^\]]*)\] \[(?<level>[^\]]*)\] (?<message>.*)$/ time_format %b %d %H:%M:%S %Y path /var/log/httpd/www.example.jp/error_log/error_log pos_file /var/log/td-agent/pos/apache.error.api.pos tag apache.error.api </source> </code> とりあえずログに残す場合は、以下の定義で。 <code> format /^(?<message>.*)$/ </code> ===== td-agent.conf -- output部のサンプル ===== 一つの入力を複数の出力に渡す <code> <match mongo.apache.access> type copy # MongoDB <store> type mongo database apache collection accesslog host localhost port 20000 flush_interval 10s </store> # to Manage <store> type forward host 192.168.0.1 port 24224 flush_interval 10s </store> </match> </code> ===== Tips ===== * [[http://fluentd.org/|公式]] * [[http://docs.fluentd.org/articles/quickstart|公式Document]] * [[http://fluentular.herokuapp.com/|Fluentular]] Fluentdのregexpのテストが可能 * [[https://gist.github.com/vananasian/4215057|fluentdでapacheのログ集約]] * fluentdでログを収集する際には、正規表現によるパースでCPUが喰われる。 * [[http://d.hatena.ne.jp/studio3104/20120824/1345795228|fluent-agent-lite と td-agent で、小さくはじめる fluentd]] * [[http://blog.livedoor.jp/sonots/archives/24617519.html|fluent-agent-lite と fluentd agent の比較(1) 〜 Haikanko OSS化への道(2)]] * [[http://blog.livedoor.jp/sonots/archives/24617573.html|fluent-agent-lite と fluentd agent の比較(2) 〜 Haikanko OSS化への道(2)]] * [[http://d.hatena.ne.jp/tagomoris/20120314/1331716214|#fluentd 用ログ収集専用のエージェント fluent-agent-lite 書いた]]
fluentd/fluentd-log.txt
· 最終更新: 2025/02/16 13:53 by
127.0.0.1
ページ用ツール
文書の表示
以前のリビジョン
バックリンク
文書の先頭へ