Fluentd插件使用方法

这里主要介绍从MongoDB同步数据到ODPS。ruby环境的搭建以及fluent_plugin_mongo_odps插件的安装。
1.准备工作
1.1安装环境要求
Ruby 2.1以上
Gem 2.4.5以上
1.2 ruby的安装首先查看你的Linux系统是否安装了ruby可以用下面两个命令查询
rpm -qa | grep ruby

yum list | grep ruby
1.3 安装一些依赖环境
执行下面的命令:
yum install gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel make bzip2 autoconf automake libtool bison iconv-devel wget tar

1.4 安装ruby步骤
(1) cd ~/
(2)wget https://ruby.taobao.org/mirrirs/ruby/ruby-2.2.3.tar.gz
(3) tar –zxvf ruby-2.2.3.rar.gz
(4) cd ruby-2.2.3
(5) ./configure
(6) make
(7) make install
1.5 修改gem库源
由于国内gem库源被墙了,访问有问题,所以将gem库换成淘宝的gem镜像源
(1) 查看当前的源地址
输入:gem sources 默认:https://rubygems.org/
(2) 删除默认的源地址
输入:gem sources –r https://rubygems.org/
注:默认的url地址后必须有”/”,否则删不掉。

(3) 添加淘宝的镜像库
输入:gem sources -a https://ruby.taobao.org/
注:国内使用淘 宝的源比较稳定,且安装或更新网速都比较快
(4) 更新源的缓存
输入:gem sources –u
更新源的缓存后即完成了Ruby的gem源修改。
最后输入 gem sources –l

2.安装Fluent-plugin-aliyun-odps
通过gem直接下载插件
输入:gem install fluent-plugin-aliyun-odps
查找默认安装路径
输入:whereis ruby
(/usr/local/lib/ruby/gems/2.2.0/gems)
screenshot

3.安装ruby driver
执行下面的命令:(A Ruby driver for MongoDB)
gem install mango

  1. 安装fluent-plugin-mongo 插件:
  2. install fluent-plugin-mongo
  3. fluent_mongo_odps.conf配置文件

type mongo_tail
host 172.16.1.157
port 27017
database test
collection mongo_small

adapter mongo
tag app.mongo

#user root
#password root

# waiting time when there is no next document. default is 1s.
wait_time 5

# Convert 'time'(BSON's time) to fluent time(Unix time).
time_key time

#disable_collection_check true



type aliyun_odps
aliyun_access_id OERGMhXn6H2mBkhk
aliyun_access_key qnuSKMKoMcY5Va97GGFtL0nvlAoLZx
aliyun_odps_endpoint http://service.odps.aliyun.com/api
aliyun_odps_hub_endpoint http://dh.odps.aliyun.com
buffer_chunk_limit 2m
buffer_queue_limit 128
flush_interval 5s
project dtstack_dev

  1. 在fluent的bin目录下启动fluent插件:
  2. –c fluent_mysql_odps.conf

执行命令,出现 Successfully import …. 表示同步数据成功
screenshot

问题1:
2016-05-27 11:12:47 +0800 [error]: unexpected error error_class=Fluent::ConfigError error=#
screenshot

解决方法:
这个问题就是导入的数据源mongo_tail只支持capped collection的数据,新建一个capped collection问题就解决了。

好的,您想了解如何使用Fluentd读写OSS,我可以为您提供一些基本信息。首先,Fluentd是一种开源的数据收集和转发引擎,它可以将来自不同数据源的数据进行聚合、过滤、转换和输出。而OSS(Object Storage Service)是阿里云提供的一种云端对象存储服务,可以用来存储和管理各种类型的非结构化数据,如图片、视频、文本等。下面是使用Fluentd读写OSS的基本步骤: 1. 安装Fluentd和相应的OSS插件。您可以在Fluentd的官网上下载和安装最新版本的Fluentd,然后使用以下命令安装OSS插件: ``` gem install fluent-plugin-oss ``` 2. 配置Fluentd。您需要在Fluentd的配置文件中添加OSS输出插件的相关信息,如OSS的访问密钥、Bucket名称、Region等。以下是一个示例配置: ``` <match oss.*> @type oss oss_key_id YOUR_ACCESS_KEY_ID oss_access_key YOUR_ACCESS_KEY_SECRET oss_bucket YOUR_BUCKET_NAME oss_region YOUR_BUCKET_REGION <buffer> @type memory flush_interval 10s </buffer> </match> ``` 3. 使用Fluentd向OSS写入数据。您可以使用Fluentd的in_tail插件来监控日志文件,并将其输出到OSS中。以下是一个示例配置: ``` <source> @type tail path /path/to/your/log/file pos_file /var/log/td-agent/your_log.pos tag oss.your_log format json <parse> @type json </parse> </source> <match oss.your_log> @type oss oss_key_id YOUR_ACCESS_KEY_ID oss_access_key YOUR_ACCESS_KEY_SECRET oss_bucket YOUR_BUCKET_NAME oss_region YOUR_BUCKET_REGION <buffer> @type memory flush_interval 10s </buffer> </match> ``` 4. 从OSS中读取数据。您可以使用Fluentd的in_oss插件来读取OSS中的数据,并将其输出到其他数据源中。以下是一个示例配置: ``` <source> @type oss oss_key_id YOUR_ACCESS_KEY_ID oss_access_key YOUR_ACCESS_KEY_SECRET oss_bucket YOUR_BUCKET_NAME oss_prefix YOUR_OBJECT_PREFIX oss_endpoint YOUR_BUCKET_ENDPOINT format json tag oss.your_data </source> <match oss.your_data> @type stdout </match> ``` 这些是使用Fluentd读写OSS的基本步骤,您可以根据自己的需求进行配置和调整。需要注意的是,使用Fluentd读写OSS可能会产生一定的费用,具体费用和计费方式可以参考阿里云的官方文档。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值