fluentdとgrothforecastをインストールする

33
FluentdとGrowthForecastの導入 FUNTERACTIVE OPEN MEETING VOL.06

Upload: regret-raym

Post on 20-Jul-2015

619 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: FluentdとGrothForecastをインストールする

FluentdとGrowthForecastの導入FUNTERACTIVE OPEN MEETING VOL.06

Page 2: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Yuji Tsukaguchiファンタラクティブ株式会社COO, Web Designer

無料写真素材サイト ぱくたそEnginner

@regret_raym

Page 3: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Fluentdとは?

・Rubyで書かれたログ収集基盤ソフトウェア

・ログ等のデータをJSON形式に変換する

・input / output / bufferの3つの構成

・プラグインアーキテクチャなので拡張性が高く、プラグ

インも200以上配布されている

http://www.fluentd.org/

Page 4: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Architecture

http://www.fluentd.org/architecture

Page 5: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Architecture

■ input

データを取り出す !■ output

データを整形して保存する

!

■ buffer

データを管理する

プラグインで構成

http://www.fluentd.org/architecture

Page 6: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

ファイル

Architecture

http://knowledge.sakura.ad.jp/tech/1336/

Fluentd

アプリ

syslog

・ ・ ・

in_tall

in_forward

in_syslog

out_forward

out_mongo

out_file

inputプラグイン outputプラグイン

別ホスト

MongoDB

ファイル

Page 7: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

代表的なinputプラグイン

プラグイン名 説明

in_forwardTCP/IPを使ってイベントを受け取る。主にほかのfluentdや各言語向けのロギングモジュールからイベントを受け取るのに使われる

in_http HTTPのPOSTリクエスト経由でイベントを受け取る

in_tailテキストファイルを監視し、そこに書き込まれたテキストをイベントとして受け取る

in_exec指定された外部プログラムを実行し、その出力をイベントとして受け取る。指定されたプログラムは永続的、もしくは指定された時間間隔で定期的に実行される

in_syslog UDPのsyslogプロトコル経由でイベントを受け取る

in_scribeFacebookが開発したログ収集サービス「Scribe」のプロトコル経由でイベントを受け取る

Page 8: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

代表的なoutputプラグイン

プラグイン名 説明out_copy 1つ以上の出力先にログを転送する

out_null なにも出力しない

out_roundrobin 指定した1つ以上の出力先にラウンドロビンアルゴリズムを使ってログを転送する

out_stdout 標準出力にログを出力する

out_exec_filter引数としてログを与えて外部プログラムを実行し、その入力をイベントとして受け取る

out_forward ほかのfluentdにネットワーク経由でログを転送する

out_mongo MongoDBにログを記録する

out_mongo_replset MongoDBにログを記録する out_exec 引数としてログを与えて外部プログラムを実行する

out_file 指定したファイルにログを記録する

out_s3 Amazon S3ストレージにログを記録する

out_webhdfsQ HDFS(Hadoop Distributed File System)にログを記録する

Page 9: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

構成

GrouthForcast

GrothForecastサーバ

fluent-agent-lite

Fluentdサーバ

fluent-plugin-growthforecast

fluent-plugin-parser

Fluentd

その他

Apache

Apacheサーバ

Page 10: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Apache

Page 11: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Apacheサーバの構成

サーバ ■構成例

・IP: 192.168.33.50

・CentOS 6.5

・Apache

・fluend-agent-lite

fluent-agent-lite

Apache

Page 12: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Apache ログフォーマット変更

# 変更前 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined !# 変更後 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined

ログにレスポンスタイムを出力するように変更

Page 13: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

fluent-agent-liteインストール

$ sudo wget --no-check-certificate https://

github.com/tagomoris/fluent-agent-lite/archive/

master.tar.gz

$ sudo tar -xzvf master.tar.gz

$ cd fluent-agent-lite-master/

$ sh bin/install.sh

fluent-agent-liteは「ログの転送のみ」に特化した軽量なFluentdクライアント

Page 14: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

fluent-agent-liteの設定

$ sudo vi /etc/fluent-agent-lite.conf

TAG_PREFIX="apache"

LOGS=$(cat <<"EOF"

access /var/log/httpd/access_log

EOF

)

PRIMARY_SERVER=“192.168.33.51:24224"

$ sudo /etc/init.d/fluent-agent-lite start

PRIMARY_SERVERでFluentdサーバのアドレスを、LOGSでFluentdサーバ

に転送させたいログを指定

Page 15: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Fluentd

Page 16: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Fluentdサーバの構成

収集サーバ

fluent-plugin-growthforecast

fluent-plugin-parser

Fluentd

その他

■構成例

・IP: 192.168.33.51

・CentOS 6.5

・Fluentd( td-agent )

・Fluentdプラグイン

Page 17: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

インストール

・DMGインストーラでFluentdをインストールする (Mac OS X)

・RPMパッケージからFluentdをインストールする (Redhat

Linux)

・DebパッケージからFluentdをインストールする (Ubuntu/

Debian Linux)

・Ruby GemでFluentdをインストールする

・ChefでFluentdをインストールする

・Fluentdをソースコードからインストールする

Page 18: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

インストール

# td-agent (fluentdの安定版配布パッケージ)

$ curl -L http://toolbelt.treasuredata.com/sh/install-redhat.sh ¦ sh

# root権限で実行に変更

$ sudo vi /etc/sysconfig/td-agent

DAEMON_ARGS="--user root"

TD_AGENT_ARGS="/usr/sbin/td-agent --group root --log /var/log/td-agent/td-agent.log”

!# 起動

$ sudo /etc/init.d/td-agent start

$ sudo chkconfig td-agent on

!# 動いているかテスト

$ curl -X POST -d 'json={"json":"message"}' http://localhost:8888/debug.test

$ sudo cat /var/log/td-agent/td-agent.log

Page 19: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

プラグインのインストール

# Growthforecastプラグインのインストール例

sudo /usr/lib64/fluent/ruby/bin/fluent-gem

install fluent-plugin-growthforecast

Page 20: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Fluentdの設定

sourceディレクティブはイベントの受信方法の指定 !<source> type <使用するプラグイン> <設定項目1> <設定値1> <設定項目2> <設定値2> : : </source>

/etc/td-agent/td-agent.conf

Page 21: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Fluentdの設定

例 <source> type tail ←in_tailプラグインを指定 path /var/log/httpd/access_log ←アクセスログのパスを指定 tag apache.access ←ログに付けるタグを指定 pos_file /var/log/td-agent/httpd-access_log.pos format apache ←パースするためにログの書式を指定 </source> !※formatはApacheのログフォーマットに合わせる必要があるため、変更した場合は正規表現で記述する ※その場合、time_formatも指定する

/etc/td-agent/td-agent.conf

Page 22: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Fluentdの設定

matchディレクティブは、受信したイベント処理 !<match <条件文>> type <使用するプラグイン> <設定項目1> <設定値1> <設定項目2> <設定値2> : : </match>

/etc/td-agent/td-agent.conf

Page 23: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

Fluentdの設定

例 <match apache.access> ←対象とするタグを指定 type file ←out_fileプラグインを指定 path /var/log/td-agent/httpd/access.log ←出力先ファイルを指定 time_slice_format %Y%m%d ←ファイル名に含める日時情報を指定 time_slice_wait 10m ←ログ記録を継続する時間を指定 compress gzip ←ログをgzip形式で圧縮 </match>

/etc/td-agent/td-agent.conf

Page 24: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

実際には

・Apacheサーバから受け取ったログをパースして、「fluent-plugin-

growthforecast」プラグインを使用して、GrothForecastに送信する

!

・ログに必要がないものがあれば、「fluent-plugin-rewrite」プラグ

インで削除したり、レスポンスタイムの単位を変換する「fluent-

plugin-forest」などを使用してFluentdから生成するデータを最適化

する

Page 25: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

GrowthForecast

Page 26: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

収集サーバの構成

グラフサーバ ■構成例

・IP: 192.168.33.53

・CentOS 6.5

・GrothForecastGrouthForcast

Page 27: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

GrowthForecastとは?

・Webサーバとして起動し、データをWeb API経由でグ

ラフ化できるツール

・Fluentdと組み合わせて、サーバリソースの負荷確認な

どにお手軽で便利

Page 28: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

インストール

# 関係モジュールをインストール & グラフ文字化け対策

$ sudo yum groupinstall "Development Tools"

$ sudo yum install pkgconfig glib2-devel gettext libxml2-devel pango-

devel cairo-devel

$ sudo yum install -y ipa-gothic-fonts ipa-mincho-fonts ipa-pgothic-fonts

ipa-pmincho-fonts

!# GrowthForecast用のユーザー作成

$ sudo useradd growthforecast

$ sudo passwd growthforecast

$ su frowthforecast

Page 29: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

インストール

# perlbrewをインストール

$ curl -kL http://install.perlbrew.pl ¦ bash

$ cd

$ echo '[[ -s "$HOME/perl5/perlbrew/etc/bashrc" ]] && source "$HOME/

perl5/perlbrew/etc/bashrc"' >> .bash_profile

$ source $HOME/perl5/perlbrew/etc/bashrc

# Perlのバージョンを確認、偶数番号をインストール

$ perlbrew available

$ perlbrew install perl-5.20.1

$ perlbrew switch perl-5.20.1

$ perl -v

$ perlbrew install-cpanm

Page 30: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

インストール

# GrowthForecastをインストール

$ git clone https://github.com/kazeburo/GrowthForecast.git

$ cd GrowthForecast

$ cpanm --installdeps .

$ exit

!# GrowthForecastの起動スクリプト作成

$ cd && wget -nd -O - https://github.com/hiro-su/gf-sample/archive/master.tar.gz¦tar zxvf -

$ cd gf-sample-master

$ sudo cp -rp growthforecast /etc/init.d

$ sudo chmod +x /etc/init.d/growthforecast

$ sudo mkdir /var/run/growthforecast

$ sudo mkdir /var/log/growthforecast

$ sudo /etc/init.d/growthforecast start

Page 31: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

GrowthForecast API

http://growthforecast/api/service_name/

section_name/graph_name

curl -F number=10 http://localhost:5125/api/

192.168.33.53/apache/response_time

Page 32: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

GrowthForecastの実行例

Page 33: FluentdとGrothForecastをインストールする

FUNTERACTIVE OPEN MEETING VOL.06 

ご清聴ありがとうございました