摘要:Fluentd + MongoDB + PHP
需要裝Fluentd 、MongoDB、MongoDB Output Plugin
MongoDB 安裝參考
http://www.dotblogs.com.tw/newmonkey48/archive/2012/09/28/75145.aspx
Fluentd儲存至MongoDB參考
http://docs.fluentd.org/articles/apache-to-mongodb
安裝
http://docs.fluentd.org/articles/apache-to-mongodb
MongoDB Output Plugin 預設安裝就會有,如果是gem,則要另外安裝
再此不多講。
out_mongo
is included in td-agent by default. Fluentd gem users will need to install the fluent-plugin-mongo gem using the following command.
接著設定conf,指向MongoDB
cd /etc/td-agent
sudo vi td-agent.conf 加入以下資訊(參考範例)
<match mongo.**> type mongo host fluentd port 27017 database fluentd collection test # for capped collection capped capped_size 1024m # authentication user michael password jordan # flush flush_interval 10s </match>
進階設定
如果是要A Server Fluentd 連接 B Server Fluentd ,做Buffer 傳輸時
http://docs.fluentd.org/articles/in_forward
則A Server 設定如下
<match fluentd.*>
type forward
<server>
host xxxxxx
port 24224
</server>
</match>
則B Server MongoDB 設定如原本那樣。
在config中,預設就有
<source>
type forward
</source>
port
The port to listen to. Default Value = 24224
bind
The bind address to listen to. Default Value = 0.0.0.0 (all addresses)
這用來監聽來外的Fluentd資訊
https://github.com/fluent/fluent-logger-php
PHP端程式如下
$logger = new FluentLogger("localhost","24224");
$logger->post(tag,message);
MongoDB config 可使用tag來設定collection
加入
<match fluent.*>
type mongo
database database_name
tag_mapped
remove_tag_prefix fluent
collection no_timestamp
user user_name
password password
flush_interval 1s
</match>