Fork me on GitHub

mongo-connector导入数据到Es

要求

基于mongo-connector同步数据,必须要求mongodb为复制集架构,原因是此插件是基于oplog操作记录进行数据同步的;而oplog可以说是Mongodb Replication的纽带。具体参见: http://www.mongoing.com/oplog

  • 启动复制集: ./bin/mongod --dbpath /path/to/database --logpath /path/to/log --fork --port 27017 --replSet rs0

  • 配置:

  • rsconf = {
        _id:'rs0',
        members:
        [
            {_id:0,
            host:'192.168.111.11:27017'
            }
        ]
    }

     

  • 初始化配置:rs.initiate(rsconf)

安装相关插件

本机环境phthon2.6,如果没有pip命令,执行easy_install pip,安装pip;如果easy_install也没有,就用它:sudo yum install python-setuptools

  • pip install mongo-connector
  • pip install elastic_doc_manager

开始同步

  • mongo-connector -m localhost:27017 -t eshost:9200 -d elastic_doc_manager

 

  • 在mongodb中插入数据:db.infos.insert({"message":"测试日志"})
  • es中查看

 

问题

ReadTimeoutError(HTTPConnectionPool(host=u'', port=9200): Read timed out. (read timeout=10))

  • 找到/usr/lib/python2.6/site-packages/mongoconnector/docmanagers目录下:elasticdocmanager.py
  • 修改self.elastic = Elasticsearch(hosts=url,**client_options)
  • 修改为self.elastic = Elasticsearch(hosts=url, timeout=200,**client_options)即可

具体配置参数详见:

 


 

测试

 

mongodb导入20多万条数据:

mongoimport --db shakespeare --collection shakespearedata --file wenjian.json --host 0.0.0.0:27017

 

mongo-connector同步了2分钟左右;暂时没有发现其他问题!

 

posted @ 2017-05-12 11:32  迁梦余光  阅读(665)  评论(0编辑  收藏  举报