這里主要介紹從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)
3.安裝ruby driver
執行下面的命令:(A Ruby driver for MongoDB)
gem install mango
- 安裝fluent-plugin-mongo 插件:
- install fluent-plugin-mongo
- 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
- 在fluent的bin目錄下啟動fluent插件:
- –c fluent_mysql_odps.conf
執行命令,出現 Successfully import …. 表示同步數據成功
問題1:
2016-05-27 11:12:47 +0800 [error]: unexpected error error_class=Fluent::ConfigError error=#
解決方法:
這個問題就是導入的數據源mongo_tail只支持capped collection的數據,新建一個capped collection問題就解決了。