ElasticSearch有一个叫做river的插件式模块,可以将外部数据源中的数据导入elasticsearch并在上面建立索引。River在集群上是单例模式的,它被自动分配到一个节点上,当这个节点挂掉后,river会被自动分配到另外的一个节点上。目前支持的数据源包括:Wikipedia, MongoDB, CouchDB, RabbitMQ, RSS, Sofa, JDBC, FileSystem,Dropbox等。River有一些指定的规范,依照这些规范可以开发适合于自己的应用数据的插件。

1、安装MongoDB的River:https://github.com/richardwilly98/elasticsearch-river-mongodbhttp://blog.csdn.net/huwei2003/article/details/40407555

git clone https://github.com/richardwilly98/elasticsearch-river-mongodb.git
cd elasticsearch-river-mongodb

git tag
git checkout elasticsearch-river-mongodb-2.0.5
mvn clean
mvn compile
mvn package vim install-local.sh --把plugin --remove 改成 plugin remove;注释掉最后一行sudo命令,因为没有plugin命令的url参数了。
./install-local.sh 
cd target/releases/

cd /usr/share/elasticsearch/plugins/

mkdir mongodb

cd mongodb

mv /data/elasticsearch-river-mongodb/target/releases/elasticsearch-river-mongodb-2.0..zip ./

cd ../head/

cp plugin-descriptor.properties ../mongodb/

cd -

vim plugin-descriptor.properties     --修改description,name的信息为mongo

mkdir _site

cp -r /data/elasticsearch-river-mongodb/src/site/* /usr/share/elasticsearch/plugins/mongodb/_site/   --复制mongo网站目录到plugins/mongodb/_site

cd _site

service elasticsearch restart

2、浏览器输入:http://192.168.7.131:9200/_plugin/mongodb/

3、配置Mongo&ElasticSearch数据互通:https://github.com/richardwilly98/elasticsearch-river-mongodb/wikihttp://blog.csdn.net/huwei2003/article/details/40407555

创建river并索引的标准模版如下:

$ curl -XPUT "localhost:9200/_river/${es.river.name}/_meta" -d '
{
"type": "mongodb",
"mongodb": {
"servers":
[
{ "host": ${mongo.instance1.host}, "port": ${mongo.instance1.port} },
{ "host": ${mongo.instance2.host}, "port": ${mongo.instance2.port} }
],
"options": {
"secondary_read_preference" : true,
"drop_collection": ${mongo.drop.collection},
"exclude_fields": ${mongo.exclude.fields},
"include_fields": ${mongo.include.fields},
"include_collection": ${mongo.include.collection},
"import_all_collections": ${mongo.import.all.collections},
"initial_timestamp": {
"script_type": ${mongo.initial.timestamp.script.type},
"script": ${mongo.initial.timestamp.script}
},
"skip_initial_import" : ${mongo.skip.initial.import},
"store_statistics" : ${mongo.store.statistics},
},
"credentials":
[
{ "db": "local", "user": ${mongo.local.user}, "password": ${mongo.local.password} },
{ "db": "admin", "user": ${mongo.db.user}, "password": ${mongo.db.password} }
],
"db": ${mongo.db.name},
"collection": ${mongo.collection.name},
"gridfs": ${mongo.is.gridfs.collection},
"filter": ${mongo.filter}
},
"index": {
"name": ${es.index.name},
"throttle_size": ${es.throttle.size},
"bulk_size": ${es.bulk.size},
"type": ${es.type.name}
"bulk": {
"actions": ${es.bulk.actions},
"size": ${es.bulk.size},
"concurrent_requests": ${es.bulk.concurrent.requests},
"flush_interval": ${es.bulk.flush.interval}
}
}
}'

一些配置项的解释如下,具体可以查看github的wiki:

  • db为同步的数据库名,
  • host mongodb的ip地址(默认为localhost)
  • port mongodb的端口
  • collection 要同步的表名
  • fields 要同步的字段名(用逗号隔开,默认全部)
  • gridfs 是否是gridfs文件(如果collection是gridfs的话就设置成true)
  • local_db_user local数据库的用户名(没有的话不用写)
  • local_db_password local数据库的密码(没有的话不用写)
  • db_user 要同步的数据库的密码(没有的话不用写)
  • db_password 要同步的数据库的密码(没有的话不用写)
  • index.name 要建立的索引名,最好是小写(应该是必须小写,并且索引名称必须唯一,之前不能存在,建议使用“数据库名+集合名+index”方式命名)
  • index:type collection名,即该索引对应的数据集合名
  • type 类型  后面是 mongodb 因为用的是 mongodb 数据库
  • bulk_size 批量添加的最大数
  • bulk_timeout 批量添加的超时时间

例如添加mongodb数据到elasticsearch里面:

curl -XPUT "http://ip地址:端口号/river_dbname/collectionname/_meta" -d'
{
"type":"mongodb",
"mongodb":{
"servers":[
{"host":"mongodb的ip地址","port":mongodb的访问端口},
{"host":"mongodb的ip地址","port":mongodb的访问端口},
{"host":"mongodb的ip地址","port":mongodb的访问端口}
],
"db":"dbname", (实际数据库名称)
"collection":"collectionname", (实际集合名称)
"gridfs":false,
"credentials":[
{ "db": "admin", "user": "user", "password": "user" }
],
"options":{
"secondary_read_preference":true (使用副本集)
}
},
"index":{
"name":"collectionname_index", (全部小写字母)
"type":"collectionname" (实际集合名称)
}
}'

添加成功,如下图:

使用head插件观察结果:

也可以通过get方式获取

GET /river_dbname/collectionname/_meta

转:

http://blog.csdn.net/huwei2003/article/details/40407555

http://www.yuansir-web.com/2015/03/06/elasticsearch%E4%B8%8Emongodb-%E6%95%B0%E6%8D%AE%E5%90%8C%E6%AD%A5%E5%8F%8A%E5%88%86%E5%B8%83%E5%BC%8F%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA-%EF%BC%88%E4%B8%80%EF%BC%89/

Linux安装ElasticSearch与MongoDB分布式集群环境下数据同步的更多相关文章

  1. elasticsearch与mongodb分布式集群环境下数据同步

    1.ElasticSearch是什么 ElasticSearch 是一个基于Lucene构建的开源.分布式,RESTful搜索引擎.它的服务是为具有数据库和Web前端的应用程序提供附加的组件(即可搜索 ...

  2. 在Hadoop1.2.1分布式集群环境下安装hive0.12

    在Hadoop1.2.1分布式集群环境下安装hive0.12 ● 前言: 1. 大家最好通读一遍过后,在理解的基础上再按照步骤搭建. 2. 之前写过两篇<<在VMware下安装Ubuntu ...

  3. 分布式集群环境下,如何实现session共享三(环境搭建)

    这是分布式集群环境下,如何实现session共享系列的第三篇.在上一篇:分布式集群环境下,如何实现session共享二(项目开发)中,准备好了一个通过原生态的servlet操作session的案例.本 ...

  4. 分布式集群环境下,如何实现session共享五(spring-session+redis 实现session共享)

    这是分布式集群环境下,如何实现session共享系列的第五篇.在上一篇:分布式集群环境下,如何实现session共享四(部署项目测试)中,针对nginx不同的负载均衡策略:轮询.ip_hash方式,测 ...

  5. 分布式集群环境下,如何实现session共享四(部署项目测试)

    这是分布式集群环境下,如何实现session共享系列的第四篇.在上一篇:分布式集群环境下,如何实现session共享三(环境搭建)中,已经准备好了相关的环境:tomcat.nginx.redis.本篇 ...

  6. 分布式集群环境下,如何实现session共享二(项目开发)

    在上一篇分布式集群环境下,如何实现session共享一(应用场景)中,介绍了在分布式集群下,需要实现session共享的应用场景.并且最后留下了一个问题:在集群环境下,如何实现session的共享呢? ...

  7. 基于HBase Hadoop 分布式集群环境下的MapReduce程序开发

    HBase分布式集群环境搭建成功后,连续4.5天实验客户端Map/Reduce程序开发,这方面的代码网上多得是,写个测试代码非常容易,可是真正运行起来可说是历经挫折.下面就是我最终调通并让程序在集群上 ...

  8. 分布式集群环境下,如何实现session共享一(应用场景)

    在web应用中,由于http的请求响应式,无状态.要记录用户相关的状态信息,比如电商网站的购物车,比如用户是否登录等,都需要使用session.我们知道session是由servlet容器创建和管理, ...

  9. 分布式集群环境下运行Wordcount程序

    1.分布式环境的Hadoop提交作业方式与本地安装的Hadoop作业提交方式相似,但有两点不同: 1)作业输入输出都存储在HDFS 2)本地Hadoop提交作业时将作业放在本地JVM执行,而分布式集群 ...

随机推荐

  1. UltraISO制作U盘启动盘安装Win7/9/10系统攻略

    U盘安装好处就是不用使用笨拙的光盘,光盘还容易出现问题,无法读取的问题.U盘体积小,携带方便,随时都可以制作系统启动盘. U盘建议选择8G及以上大小的. 下面一步一步讲解如果制作U盘安装盘: 1.首先 ...

  2. 企业防火墙之iptables

    1.1 企业中安全优化配置原则 尽可能不给服务器配置外网ip ,可以通过代理转发或者通过防火墙映射.并发不是特别大情况有外网ip,可以开启防火墙服务. 大并发的情况,不能开iptables,影响性能, ...

  3. VC++导出具有命名空间的函数

    问题现象 原因分析 解决的方法 1 问题现象 导出具有命名空间的函数和类.源码例如以下: 头文件MiniMFC.h namespace MiniMFC { __declspec(dllexport) ...

  4. Android studio 将 Module 打包成 Jar 包

    整理记录 AndroidStudio 把一个 module 项目打包成 jar 包. 一.默认自动生成的 jar 包 众所周知 android studio 会在library所依赖的 app运行 或 ...

  5. 【Linux】好玩的Linux命令(二)

    关于Linux talk:http://man.linuxde.net/talk 下面文章转自:http://www.oschina.net/translate/11-lesser-known-use ...

  6. PPT里面的背景音乐找不到?

      ppt,找不到播放器,却有音乐播放!如何实现? 原来是在幻灯片切换处的音效添加的音乐~   文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论

  7. lambda expressions are not supported at this language level

    IDEA下报错:lambda expressions are not supported at this language level 解决: 1. File -> Project Struct ...

  8. Java中String、StringBuffer和StringBuilder的区别

    转载请注明原文地址:http://www.cnblogs.com/ygj0930/p/6581009.html  在编程中,对于字符串拼接,我们可以用String类重载的+或concat(str).S ...

  9. VIM自定义快捷键 abort

    "在选择模式下系统级复制 vmap ,c "+y<ESC>vmap ,C "+Y<ESC>"在选择模式下系统级剪切vmap ,x x:l ...

  10. V-rep学习笔记:视觉传感器1

    Vision sensors, which can detect renderable entities(Renderable objects are objects that can be seen ...