MongoDB 4.x实时同步到ElasticSearch 6.x+;
我试图找到一种简单的方法,将mongoDB 4.x中的数据同步到elasticsearch 6.x。我的用例用于elasticsearch支持但mongodb不支持的部分文本搜索。MongoDB是我的应用程序的主要数据库 我发现的所有解决方案似乎都过时了,只支持旧版本的mongoDB/elasticsearch。其中包括mongodb连接器、mongodb河MongoDB 4.x实时同步到ElasticSearch 6.x+;,mongodb,elasticsearch,spring-data-mongodb,Mongodb,elasticsearch,Spring Data Mongodb,我试图找到一种简单的方法,将mongoDB 4.x中的数据同步到elasticsearch 6.x。我的用例用于elasticsearch支持但mongodb不支持的部分文本搜索。MongoDB是我的应用程序的主要数据库 我发现的所有解决方案似乎都过时了,只支持旧版本的mongoDB/elasticsearch。其中包括mongodb连接器、mongodb河 使用什么工具可以使mongoDB中数据的任何更改(CRUD)自动同步到elasticsearch 有一个叫做Monstach的工具,用于将
使用什么工具可以使mongoDB中数据的任何更改(CRUD)自动同步到elasticsearch 有一个叫做Monstach的工具,用于将MOngoDB数据实时迁移到ElasticSearch。此工具支持最新的MongoDB版本 它的同步守护进程是用Go编写的,它可以将MongoDB集合连续索引到Elasticsearch中。Monstach使您能够使用Elasticsearch对MongoDB数据进行复杂的搜索和聚合,并轻松构建实时Kibana可视化和仪表盘 它是一个go守护进程,可以实时将mongodb同步到elasticsearch。 这是小胡子。其网址为: Monstach要求mongodb以复制模式运行 在初始设置下面配置和使用它 步骤1:
C:\Program Files\MongoDB\Server\4.0\bin>mongod --smallfiles --oplogSize 50 --replSet test
步骤2:
C:\Program Files\MongoDB\Server\4.0\bin>mongo
C:\Program Files\MongoDB\Server\4.0\bin>mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.2
Server has startup warnings:
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten]
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten]
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2019-01-18T16:56:44.931+0530 I CONTROL [initandlisten]
MongoDB Enterprise test:PRIMARY>
第四步。
下载「https://github.com/rwynn/monstache/releases".
解压缩下载并调整PATH变量,以包含平台文件夹的路径。
转到cmd并键入“monstach-v”
# 4.13.1
Monstach使用TOML格式进行配置。配置名为config.toml的迁移文件
第五步
My config.toml-->
第六步
D:\15-1-19>monstache -f config.toml
如果您与docker合作,您可以获得本教程 Monstache是一个用Go编写的同步守护进程,它可以将MongoDB集合连续索引到Elasticsearch中。Monstach使您能够使用Elasticsearch对MongoDB数据进行复杂的搜索和聚合,并轻松构建实时Kibana可视化和仪表盘。 Monstach文档:
github:
docker-compose.yml
version: '2.3'
networks:
test:
driver: bridge
services:
db:
image: mongo:3.0.2
expose:
- "27017"
container_name: mongodb
volumes:
- ./mongodb:/data/db
- ./mongodb_config:/data/configdb
ports:
- "27018:27017"
command: mongod --smallfiles --replSet rs0
networks:
- test
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.7
container_name: elasticsearch
volumes:
- ./elastic:/usr/share/elasticsearch/data
- ./elastic/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
ports:
- 9200:9200
command: elasticsearch -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_
healthcheck:
test: "wget -q -O - http://localhost:9200/_cat/health"
interval: 1s
timeout: 30s
retries: 300
ulimits:
nproc: 65536
nofile:
soft: 65536
hard: 65536
memlock:
soft: -1
hard: -1
networks:
- test
monstache:
image: rwynn/monstache:rel4
expose:
- "8080"
ports:
- "8080:8080"
container_name: monstache
command: -mongo-url=mongodb://db:27017 -elasticsearch-url=http://elasticsearch:9200 -direct-read-namespace=Product_DB.Product -direct-read-split-max=2
links:
- elasticsearch
- db
depends_on:
db:
condition: service_started
elasticsearch:
condition: service_healthy
networks:
- test
replicaset.sh
#!/bin/bash
# this configuration is so important
echo "Starting replica set initialize"
until mongo --host 192.168.144.2 --eval "print(\"waited for connection\")"
do
sleep 2
done
echo "Connection finished"
echo "Creating replica set"
mongo --host 192.168.144.2 <<EOF
rs.initiate(
{
_id : 'rs0',
members: [
{ _id : 0, host : "db:27017", priority : 1 }
]
}
)
EOF
echo "replica set created"
#/bin/bash
#这个配置非常重要
echo“启动副本集初始化”
直到mongo--主机192.168.144.2--评估“打印(\“等待连接\”)为止
做
睡眠2
完成
回显“连接完成”
回显“创建副本集”
mongo--已创建主机192.168.144.2副本集
$docker下线
4) 运行终端
$docker整理
最后
MongoDB中的复制
副本集是维护同一数据集的一组实例。副本集包含多个数据承载节点和一个仲裁器节点(可选)。在数据承载节点中,一个且只有一个成员被视为主节点,而其他节点被视为次节点。
接收所有写入操作。副本集只能有一个主副本,能够确认有写问题的写操作;尽管在某些情况下,另一个mongod实例可能会暂时认为自己也是主要的。
查看副本集配置。
使用
副本集允许您将MongoDB集合索引到Elasticsearch en实时同步中。您知道Monstach是否支持MongoDB 4.x和Elasticsearch 7.x吗?该网站声称支持最新版本,但没有说明是哪个版本。想知道是否有人在这些版本上试用过它?它确实支持这两个版本的最新版本。我已经核实过了。告诉您版本兼容性…Monstach将满足您的需要。我已经建立了一个博客,很容易复制和粘贴尝试。可能会帮助某人
version: '2.3'
networks:
test:
driver: bridge
services:
db:
image: mongo:3.0.2
expose:
- "27017"
container_name: mongodb
volumes:
- ./mongodb:/data/db
- ./mongodb_config:/data/configdb
ports:
- "27018:27017"
command: mongod --smallfiles --replSet rs0
networks:
- test
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.7
container_name: elasticsearch
volumes:
- ./elastic:/usr/share/elasticsearch/data
- ./elastic/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
ports:
- 9200:9200
command: elasticsearch -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_
healthcheck:
test: "wget -q -O - http://localhost:9200/_cat/health"
interval: 1s
timeout: 30s
retries: 300
ulimits:
nproc: 65536
nofile:
soft: 65536
hard: 65536
memlock:
soft: -1
hard: -1
networks:
- test
monstache:
image: rwynn/monstache:rel4
expose:
- "8080"
ports:
- "8080:8080"
container_name: monstache
command: -mongo-url=mongodb://db:27017 -elasticsearch-url=http://elasticsearch:9200 -direct-read-namespace=Product_DB.Product -direct-read-split-max=2
links:
- elasticsearch
- db
depends_on:
db:
condition: service_started
elasticsearch:
condition: service_healthy
networks:
- test
#!/bin/bash
# this configuration is so important
echo "Starting replica set initialize"
until mongo --host 192.168.144.2 --eval "print(\"waited for connection\")"
do
sleep 2
done
echo "Connection finished"
echo "Creating replica set"
mongo --host 192.168.144.2 <<EOF
rs.initiate(
{
_id : 'rs0',
members: [
{ _id : 0, host : "db:27017", priority : 1 }
]
}
)
EOF
echo "replica set created"