MySQLプラグインのインストール
td-agent-gem
コマンドを利用して、mysql2とfluent-plugin-mysqlを導入します。
- 実行例
# td-agent-gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.4.9
Parsing documentation for mysql2-0.4.9
Installing ri documentation for mysql2-0.4.9
Done installing documentation for mysql2 after 0 seconds
1 gem installed
# td-agent-gem install fluent-plugin-mysql
Fetching: mysql2-cs-bind-0.0.6.gem (100%)
Successfully installed mysql2-cs-bind-0.0.6
Fetching: ruby_dig-0.0.2.gem (100%)
Successfully installed ruby_dig-0.0.2
Fetching: strptime-0.1.9.gem (100%)
Building native extensions. This could take a while...
Successfully installed strptime-0.1.9
Fetching: serverengine-2.0.5.gem (100%)
Successfully installed serverengine-2.0.5
Fetching: msgpack-1.1.0.gem (100%)
Building native extensions. This could take a while...
Successfully installed msgpack-1.1.0
Fetching: fluentd-0.14.20.gem (100%)
Successfully installed fluentd-0.14.20
Fetching: fluent-plugin-mysql-0.2.1.gem (100%)
Successfully installed fluent-plugin-mysql-0.2.1
Parsing documentation for mysql2-cs-bind-0.0.6
Installing ri documentation for mysql2-cs-bind-0.0.6
Parsing documentation for ruby_dig-0.0.2
Installing ri documentation for ruby_dig-0.0.2
Parsing documentation for strptime-0.1.9
Installing ri documentation for strptime-0.1.9
Parsing documentation for serverengine-2.0.5
Installing ri documentation for serverengine-2.0.5
Parsing documentation for msgpack-1.1.0
Installing ri documentation for msgpack-1.1.0
Parsing documentation for fluentd-0.14.20
Installing ri documentation for fluentd-0.14.20
Parsing documentation for fluent-plugin-mysql-0.2.1
Installing ri documentation for fluent-plugin-mysql-0.2.1
Done installing documentation for mysql2-cs-bind, ruby_dig, strptime, serverengine, msgpack, fluentd, fluent-plugin-mysql after 6 seconds
7 gems installed
プラグインの導入時に前提となっているライブラリ(libmysqlclient)などがありますので、導入時にOSに合わせてご確認ください。
http://www.rubydoc.info/gems/fluent-plugin-mysql/0.0.8#Prerequisites
実行時に以下のエラーが発生する場合は、MySQLのプラグインがインストールされていません。
config error file="conf/apppot-iot.conf" error="Unknown output plugin 'mysql'. Run 'gem search -rd fluent-plugin' to find plugins"
apppot-iot.confの編集
<match apppot.{Topic名}>
@type mysql
host ホスト名 port 3306
username DBユーザー
password パスワード
database apppot_jp_co_ncdc_apppot_mini4wd_1_0_0
table AccelGyro
include_time_key yes
utc
format jsonpath
sql INSERT INTO AccelGyro(objectId, accelX, accelY, serverCreateTime, scopeType, createTime, serverRecordStatus, groupIds, createUserId, time) VALUES (?, ?, ?, ?, '3', ?, '1', '{1}', '1', ?)
key_names message.accel-gyro.time, message.accel-gyro.accel_x, message.accel-gyro.accel_y, time, message.accel-gyro.time, message.accel-gyro.time
flush_interval 3s
num_threads 1
</match>