mogodb 同步数据到 ElasticSearch
1、需安装:mogodb ElasticSearch monstache
2、mogodb创建副本集
主副主开启副本集设置:
replication:
replSetName: "S1"
副机关闭防火墙,设置
net:
port: 27017
bindIp: 0.0.0.0
"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" 127.0.0.1:27017
配置:
rs.initiate( {
... _id : "S1",
... members: [
... { _id: 0, host: "192.168.1.239:27017" },
... { _id: 1, host: "192.168.1.253:27017" }, ]
... })
提示成功:{
"ok" : 0,
"errmsg" : "Our set name did not match that of the request target, requestTarget:192.168.1.253:27017",
"code" : 103,
"codeName" : "NewReplicaSetConfigurationIncompatible"
}
在monstache根目录my.con 配置:
# mongo连接串
mongo-url = "mongodb://127.0.0.1:27017"
# ES地址
elasticsearch-urls = [ "http://localhost:9200" ]
# mydb中completed_food_orders这个collection已经有数据
# 需要先将已有数据全量导到ES中
direct-read-namespaces = ["qqqun.group2"]
# 配置collection和es索引的对应关系
[[mapping]]
namespace = "qqqun.group2"
index = "group2"
#####配置结束
执行命令:monstache.exe -f my.conf