OSS編~Fluentdでout_mongoプラグインを試してみる~

こんにちは! JQです。

前回は『 OSS編~Fluentdで負荷分散を試してみる~ 』と題して、Fluentdで負荷分散を試してみました。

今回は『OSS編~Fluentdでoutmongoプラグインを試してみる~』と題して、Fluentdでoutmongoプラグインを試してみたいと思います。

MongoDB

1.インストール

先ずはMongoDBをインストールします。

レポジトリを追加します。

1$ sudo vi /etc/yum.repos.d/mongo.repo2[mongo]3name=MongoDB Repository4baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_645gpgcheck=06enabled=0

インストールを行います。

1$ sudo yum -y install mongo-10gen mongo-10gen-server --enablerepo=mongo

確認してみます。

1$ mongo --version2MongoDB shell version: 2.6.3

起動します。

1$ sudo /etc/rc.d/init.d/mongod start2Starting mongod:                                           [  OK  ]3$ sudo chkconfig mongod on

2.Fluentd設定

続いてFluentdの設定を行います。

1$ sudo vim /etc/td-agent/td-agent.conf2<source>3  type tail4  format apache25  path /var/log/apache2/access_log6  pos_file /var/log/td-agent/apache2.access_log.pos7  tag mongo.apache.access8</source>910<match mongo.*.*>1112# plugin type1314  type mongo1516# mongodb db + collection1718  database apache19  collection access2021# mongodb host + port2223  host localhost24  port 270172526# interval2728  flush_interval 10s29</match>

反映させます。

1$ sudo /etc/rc.d/init.d/td-agent restart2Shutting down td-agent:                                    [  OK  ]3Starting td-agent:                                         [  OK  ]

3.確認

それでは確認してみましょう。

WEBにアクセスしてログを出力させておきます。

MongoDBに接続して確認してみます。

1$ mongo2MongoDB shell version: 2.6.33connecting to: test4> use apache5switched to db apache6> db["access"].findOne();7{8        "_id" : ObjectId("53e0a1d0dc192407f2000001"),9        "host" : "xxx.xxx.xxx.xxx",10        "user" : null,11        "method" : "GET",12        "path" : "/",13        "code" : 403,14        "size" : 3839,15        "referer" : null,16        "agent" : "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0",17        "time" : ISODate("2014-08-05T09:20:06Z")18}19>

いかがでしたでしょうか?

次回もお楽しみに!!!

この記事を書いた人

aws-recipe-user