閱讀784 返回首頁    go 阿裏雲


Fluentd MaxCompute插件__數據入雲_數據集成-阿裏雲

Fluentd是一個日誌收集係統,它的特點在於其各部分均是可定製化的,你可以通過簡單的配置,將日誌收集到不同的地方。本文介紹如何通過Fluentd將日誌上傳到ODPS DataHub

二、環境要求

  • Ruby 2.1.0
  • Gem 2.4.5 or later
  • Fluentd-0.10.49 or later
  • Protobuf-3.5.1 or later

三、安裝步驟

安裝依賴:

gem install protobuf

gem install fluentd --no-ri --no-rdoc

安裝插件:

gem install fluent-plugin-aliyun-odps

四、配置實例

  • 創建odps datahub表:
  1. create table nginx_logs(remote string, accesstime string, method string, path string, code string, size string, agent string) into 5 shards hublifecycle 7;
  • 修改fluentd配置文件,將nigix日誌實時傳入odps datahub表。
  1. <source>
  2. type tail
  3. path /logs/access.log
  4. pos_file /tmp/nginx.access.pos
  5. refresh_interval 5s
  6. tag nginx.access
  7. format /^(?<remote>[^ ]*) - - [(?<accesstime>[^]]*)] "(?<method>S+)(?: +(?<path>[^"]*?)(?: +S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*) "-" "(?<agent>[^"]*)"$/
  8. time_format %Y%b%d %H:%M:%S %z
  9. </source>
  10. <match **>
  11. type aliyun_odps
  12. aliyun_access_id ************
  13. aliyun_access_key ************
  14. aliyun_odps_endpoint https://service.odps.aliyun.com/api/
  15. aliyun_odps_hub_endpoint https://dh.odps.aliyun.com
  16. project test
  17. buffer_chunk_limit 2m
  18. buffer_queue_limit 128
  19. flush_interval 5s
  20. <table nginx.access>
  21. table nginx_logs
  22. fields remote,accesstime,method,path,code,size,agent
  23. shard_number 5
  24. </table>
  25. </match>
  • 啟動fluentd,如果有類似如下的輸出,就可以說明數據實時寫入Datahub服務已經成功。
  1. 2015-08-19 16:41:15 +0800 [info]: 5 records to be sent
  2. 2015-08-19 16:41:15 +0800 [info]: Successfully import 5 data to table:nginx_logs at threadId:0

五、了解更多

插件GitHub地址

最後更新:2016-11-24 11:23:47

  上一篇:go Flume MaxCompute Sink插件__數據入雲_數據集成-阿裏雲
  下一篇:go OGG MaxCompute插件__數據入雲_數據集成-阿裏雲