LoginSignup
23
23

More than 5 years have passed since last update.

いまさら fluentd をはじめてみたMongoDB なにそれ美味しいの?、その3

Last updated at Posted at 2014-06-22

いまさら fluentd はじめてみる3

MongoDB これも前から気になっていたので調べてみた。EPEL パッケージでインストールするんでそこら辺は判ってると思うけどよろしく。あと「それ美味しいの?」って素では言わないのでそこんとこもよろしくw(会社の同僚が言うけどイラっとくるよねw)。

ようやっとこの構成を作れるw
fluentd_2.png

MongoDB って

いわゆる noSQL に分類される物です。特にこの MonogoDB は、ドキュメント指向型データベースでして特筆すべき点として「JSONのオブジェクトそのままDBに」っていうこと。これすごいことす。あと名前の由来が、”humongous”(ばかでかい)って始めて知りました。そりゃビックデータって語句で沢山引っ掛かるわ。

MongoDBの薄い本(The Little MongoDB Book)
はじめてのmongoDB 入門編 構築・設定・ツールまとめ
初心者向けMongoDBのキホン! - SlideShare

MongoDB いんすとーる

/etc/yum.repos.d/mongodb.repo を作成し、MongoDB をインストールします。

/etc/yum.repos.d/mongodb.repo
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
command
$ sudo yum -y install mongo-10gen mongo-10gen-server

起動と自動起動の設定

お約束のコマンド。2014/06/21現在のバージョンは MongoDB shell version: 2.6.3 らしいい。
あと MongoDB のLISTENポートは 27017(netstat -a | grep mongo でわかるよ)。

command
$ sudo /etc/init.d/mongod start
$ sudo chkconfig mongod on

MongoDBツール : http://robomongo.org/

fluentd の設定

LTSV, MongoDB も設定してるのであとは fluentd の設定だけ。

送信側(エージェント側)

Apache のログ(LTSV)を監視し fluentd サーバに転送する設定。fluentd の再起動が必要です。

/etc/td-agent/td-agent.conf
<source>
  type tail
  path /var/log/httpd/access_log
  format ltsv
  time_key time
  time_format %d/%b/%Y:%H:%M:%S %z
  tag td.apache.access
  pos_file /var/log/td-agent/apache_access.pos
  tag mongo.apache
</source>

<match mongo.**>
  type forward
  buffer_chunk_limit 256m
  buffer_queue_limit 128
  flush_interval 5s
  <server>
    host 192.168.11.106
    port 24224
  </server>
</match>

受信側(コレクター側)

転送された情報を MongoDB に追加&ファイルに書き出す設定。fluentd の再起動が必要です。

/etc/td-agent/td-agent.conf
<match mongo.**>
  type copy

  <store>
    type file
    time_slice_format %Y%m%d_%H%M
    time_slice_wait 1m
    path /var/log/td_log/td_access_test
    time_format %Y%m%dT%H%M%S%z
  </store>

  <store>
    type mongo
    database apache
    collection access
    host localhost
    port 27017
    flush_interval 10s
  </store>
</match>

MongoDB の内容を確認してみる

きっとここまでくればGood、もーまんたい。MongoDB にデータが格納されているはず。そんな訳で確認してみよう。
192.168.11.104(Apach) ⇒ 192.168.11.106(MongoDB) にデータがはいってます!!

command
$ mongo
MongoDB shell version: 2.6.3
connecting to: test
> show dbs
admin   (empty)
apache  0.078GB
local   0.078GB
> use apache
switched to db apache
> show collections
access
system.indexes
> db.access.find();
{ "_id" : ObjectId("53a6bdcb297b502c2a000001"), "domain" : "192.168.11.104", "host" 

次は

GrowthForecast を使った方法を勉強してみる(その4)の予定ですw

参考サイト

さくらサーバーのVPS環境にfluentdとMongoDBをインストール
リッスンするipを指定する

23
23
0

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
23
23