栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Monstache: MongoDB数据导入ES

Monstache: MongoDB数据导入ES

1. Monstache介绍

monstache是一个Go语言开发的开源工具,可以将MongoDB中的数据实时地导入到Elasticsearch中,从而分析搜索这些数据。

项目地址:https://github.com/rwynn/monstache

2. 安装Go语言环境

首先需要安装Go语言开发环境。

Go语言安装包下载地址:https://go.dev/

下载之后是一个压缩包。先解压到一个目录中。以Linux系统为例,解压到 /usr/local 目录中。

tar -C /usr/local -xzf go1.14.4.linux-amd64.tar.gz

然后配置环境变量:

export GOROOT=/usr/local/go
export GOPATH=/home/go/
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

在命令行运行:

go version

显示如下版本信息,说明Go语言安装OK了。

go version go1.17.7 linux/amd64
3. 安装Monstache

首先要先下载Monstache的源代码。

git clone https://github.com/rwynn/monstache.git

再选择合适的Git分支。具体使用哪个分支,可以参照官网的表格。地址是:https://rwynn.github.io/monstache-site/start/


比如ES版本是7.x。需要切换到rel6分支。

git checkout re6

切换分支后,源代码目录运行install命令编译安装。

go install

完成后,运行 monstache 命令测试下。输入 monstache -v 出现版本号就是安装成功了:

> monstache -v
6.7.7
4. 配置文件

配置文件采用toml格式。

官网有样例文件:https://rwynn.github.io/monstache-site/start/

这里提供一个简单的示例:

# mongo连接串
mongo-url = "mongodb://127.0.0.1:27017"
# ES地址
elasticsearch-urls = [ "http://localhost:9200" ]

# mydb中completed_food_orders这个collection已经有数据
# 需要先将已有数据全量导到ES中
direct-read-namespaces = ["mydb.completed_food_orders"]

# 同时关注completed_food_orders的数据变化。
change-stream-namespaces = ["mydb.completed_food_orders"]

# 打印日志
verbose = true

# 配置collection和es索引的对应关系
[[mapping]]
namespace = "mydb.completed_food_orders"
index = "completed_food_orders"

使用配置文件运行:

monstache -f my.conf
5. 常见错误

可能会碰到下面这个错误:

 Error starting change stream. Will retry: (Location40573) The $changeStream stage is only supported on replica sets

原因是:Change Stream只有在复制集模式下,writeConcern是majority的情况下才会触发。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/745514.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号