4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

fluentdインストール、mongodbに保存

Last updated at Posted at 2015-08-21
  • RaspberryPi(DietPi:Jessie), ubuntu14.04, linuxmint17.2 にて確認。

参考

インストール(deb系)

sudo apt-get install -y ruby-dev build-essential
sudo gem install fluentd --no-ri --no-rdoc
  • /usr/local/bin/fluentd が入る。

インストール(centos5系)

/etc/yum.repos.d/td.repo
[treasuredata]
name=TreasureData
baseurl=http://packages.treasure-data.com/redhat/$basearch
gpgcheck=0

gpgcheck=0が必要。

sudo yum install -y td-agent

動作確認

待ち受け
fluentd --setup ~/fluent
fluentd -c ~/fluent/fluent.conf
送信
echo '{"json":"message"}' | fluent-cat debug.test

fluentdはCtrl-Cで終了

http 8888ポートで待ち受け、ログをファイルに保存

~/fluent/fluent.conf
 <source>
   @type http
   @id http_input
   port 8888
 </source>
+<match host1>
+  type file
+  path /mnt/usb_1/fluent/host1
+</match>
  • fluentd を再立ち上げし以下実施
ログの送信
curl http://myserver:8888/host1 -F 'json={"log":"test_dayo"}'
  • /mnt/usb_1/fluent/host1.20150821.b51dc6d7e2ba239e2 に以下ログが保存される。
2015-08-21T08:52:26+09:00       host1   {"log":"test_dayo"}

apacheのproxypass機能で8888ポートを開放せずに保存

 <VirtualHost *:80>
 ...
+   ProxyPass /host1 http://localhost:8888/host1
 </VirtualHost>
sudo a2enmod proxy_http
sudo /etc/init.d/apache2 restart
ログの送信
curl http://myserver/host1 -F 'json={"log":"test_dayo"}'

ログが保存されていることを確認。

mongodbに保存

sudo apt-get install -y mongodb
/etc/mongodb.conf
- dbpath=/var/lib/mongodb
+ dbpath=/mnt/usb_1/fluent/mongodb
- logpath=/var/log/mongodb/mongodb.log
+ logpath=/mnt/usb_1/fluent/mongodb/mongodb.log

mongod -f /etc/mongodb.conf
プラグインのインストール
sudo gem i fluent-plugin-mongo --no-ri --no-rdoc
sudo gem i bson_ext --no-ri --no-rdoc
~/fluent/fluent.conf
 <match host1>
-  type file
-  path /mnt/usb_1/fluent/host1
+  type mongo
+  host localhost
+  database fluent
+  collection host1
 </match>
レコードの確認
mongo fluent
> show collections
> db.host1.find()
レコード
{ "_id" : ObjectId("55d6738290c3222278000001"), "log" : "test_dayo", "time" : ISODate("2015-08-21T00:40:12Z") }
{ "_id" : ObjectId("55d6738290c3222278000002"), "log" : "test_dayo", "time" : ISODate("2015-08-21T00:40:33Z") }
{ "_id" : ObjectId("55d673cb90c32222a0000001"), "log" : "test_dayo", "time" : ISODate("2015-08-21T00:40:53Z") }
{ "_id" : ObjectId("55d6744490c32222a0000002"), "log" : "test_dayo", "time" : ISODate("2015-08-21T00:43:42Z") }

mongodはsudo killall mongodで終了するか
Manage mongod Processes — MongoDB Manual 3.0を参照。

mongodb3.0をインストールする場合

mongodb3.0をインストール
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?