阅读784 返回首页    go 阿里云 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插件__数据入云_数据集成-阿里云