【Mongo工具】Mongo迁移工具之Mongo-shake

Mongo-Shake 简介

Mongo-Shake 是一个基于 MongoDB 操作日志(oplog)的通用服务平台。它从源 MongoDB 数据库中获取操作日志,并在目标 MongoDB 数据库中重放,或者通过不同的隧道发送到其他终端。如果目标端是 MongoDB 数据库,即直接重放操作日志,那么它就像一个同步工具,用于将数据从源 MongoDB 复制到另一个 MongoDB,以构建冗余复制或双主复制。除了这种直接方式外,还有其他类型的隧道,如rpc, file, tcp, kafka。用户编写的接收器必须分别定义自己的接口来连接这些隧道。用户还可以定义自己的可插拔隧道类型。如果连接到像 Kafka 这样的第三方消息中间件,消费者可以在发布/订阅模块中灵活地以异步方式获取订阅数据。以下是通用的数据流:

源可以是 mongod 单实例、副本集或分片集群,而目标可以是 mongod 实例或 mongos 实例。如果源是副本集,我们建议从次要节点/隐藏节点获取数据,以减轻主节点的压力。如果源是分片集群,则每个分片都应连接到 Mongo-Shake。在目标端,可以有多个 mongos 实例以保持高可用性,并且不同的数据将通过哈希算法被分配到不同的 mongos 实例中进行写入。

Parallel Replication(并行复制)

并行复制有三种选项,我们称之为“shad_key”:id、collection 和 auto。id 表示并发粒度是文档级别,而 collection 表示粒度是集合/表级别。auto 选项会根据是否存在任何集合的唯一索引来决定,如果存在唯一索引,则更改为集合级别,否则为 id 级别。

High Availability (高可用性)

Mongo-Shake 会定期将其上下文持久化到注册中心,默认情况下是源数据库。目前,上下文是检查点,它标记了成功重放操作日志的位置。同时支持超管机制,以便在 Mongo-Shake 崩溃时(根据配置中的 master_quorum)立即重启。

Filter (过滤)

支持使用白名单和黑名单过滤数据库和集合命名空间。

DDL Syncing (DDL 同步)

从 1.5 版本开始,MongoShake 支持使用全局屏障来同步 DDL。一旦获取到 DDL 操作日志,MongoShake 会添加一个屏障,使得所有后续的操作日志在队列中等待,直到这个操作日志被写入目标 MongoDB 或隧道,并且检查点被更新。目前,DDL 仅支持源端为副本集(目标端可以是副本集或分片集群),后续版本将支持分片。

Global ID (全局ID)

在阿里云内部版本中,支持全局 ID(也称为 gid),它标记了数据库的 ID。这可以用于避免两个数据库相互备份时产生的循环。Mongo-Shake 只获取与源数据库 ID 相等的操作日志,如果没有提供 gid,则会获取所有操作日志。对于当前的开源版本,由于 MongoDB 内核的修改限制,暂不支持此功能。

如果您想在不支持 gid 的情况下构建双主复制,请参阅常见问题文档以获取更多详细信息。

Tunnel (隧道)

如上所述,我们支持多种隧道类型,如:rpc、tcp、file、kafka、mock 和 direct。rpc 和 tcp 分别表示通过网络/rpc 和 TCP 同步连接到接收器;file 表示将输出写入文件;kafka 是一种异步发送消息的方式;mock 用于测试,会丢弃所有数据;direct 表示直接写入目标 MongoDB。用户还可以添加或修改当前的隧道类型。

我们提供了接收器来连接不同的隧道,如:rpc、tcp、file、mock 和 kafka。请参阅常见问题文档以获取更多详细信息。

Compressor (压缩)

在发送之前,批量操作日志支持 gzip、zlib、deflate 压缩。

Monitor & Debug (监控 &调试 )

用户可以通过 RESTful API 监控或调试 Mongo-Shake,请参阅常见问题文档以获取更多详细信息。

Other Details (其他细节)

Mongo-Shake 使用 go-driver 从源 MongoDB 获取给定配置时间戳之后的操作日志。然后,它根据白名单、黑名单和 gid 过滤操作日志。由于操作日志 DML 的幂等性,所有操作日志都将至少传输一次,这是可以接受的。我们使用 seq 和 ack 来确保数据包已被接收,这与 TCP 中的序列号和确认号类似。

操作日志在处理管道中被批量处理。

用户可以根据不同的环境调整工作线程并发度和执行器并发度。

如果您想查看更多详细信息,请参阅文章开头列出的详细文档。

Code branch rules (代码分支规则)

版本号规则:a.b.c

a:主版本号
b:次版本号。偶数表示稳定版本。例如,1.2.x、1.4.x、2.0.x 是稳定版本,而 1.5.x、2.1.x 则不是。
c:修补版本号

branch namerules
mastermaster branch, do not allowed push code. store the latest stable version.
develop(main branch)develop branch. all the bellowing branches fork from this.
feature-*new feature branch. forked from develop branch and then merge back after finish developing, testing, and code review.
bugfix-*bugfix branch. forked from develop branch and then merge back after finish developing, testing, and code review.
improve-*improvement branch. forked from develop branch and then merge back after finish developing, testing, and code review.

Usage (使用说明)

在OSX和Linux系统上,分别运行已构建的./bin/collector.darwin或collector.linux。

或者,你可以根据以下步骤自行构建mongo-shake(需要go版本>=1.15.10):

​
git clone https://github.com/alibaba/MongoShake.git
cd MongoShake
make
./bin/collector -conf=conf/collector.conf
​

请注意:用户必须先修改collector.conf以满足需求。您还可以使用"start.sh"脚本,但该脚本仅在Linux操作系统上支持虚拟化机制。

Shake series tool (Shake系列工具)

我们还提供了一些用于Shake系列同步的工具。

MongoShake:mongodb数据同步工具。
RedisShake:redis数据同步工具。
RedisFullCheck:redis数据同步验证工具。


安装

1 下载二进制 

https://github.com/alibaba/MongoShake/releases

解压之后会出现以下文件:

 

目录下会生成多个架构(Windows,liunx等)的collector二进制文件,按自己的平台修改名字,如linux平台则是把collector.linux改为collector

mv collector.linux collector

 

查看命令帮助

$  ./collector --help
Usage of ./collector:
  -conf string
    	configure file absolute path
  -verbose int
    	where log goes to: 0 - file,1 - file+stdout,2 - stdout
  -version
    	show version

# 查看版本

$  ./collector -version
improve-2.8.4,9af224464481f877c761963aa4bad71573657269,release,go1.15.10,2023-04-25_17:26:40

 

 -conf 配置文件

 -version 版本信息

 -verbose 日志输出 0:文件 1 :文件+屏幕标准输出 2 屏幕输出

2 配置文件

目录下的配置文件 注释比较详细,建议仔细仔细阅读

$ cat collector.conf
# if you have any problem, please visit https://github.com/alibaba/MongoShake/wiki/FAQ
# for the detail explanation, please visit xxxx
# 如果有问题,请先查看FAQ文档以及wiki上的说明。
# 关于各个参数的详细说明,请参考:xxx

# current configuration version, do not modify.
# 当前配置文件的版本号,请不要修改该值。
conf.version = 10

# --------------------------- global configuration ---------------------------
# collector name
# id用于输出pid文件等信息。
id = mongoshake

# high availability option.
# enable master election if set true. only one mongoshake can become master
# and do sync, the others will wait and at most one of them become master once
# previous master die. The master information stores in the `mongoshake` db in the source
# database by default.
# This option is useless when there is only one mongoshake running.
# 如果开启主备mongoshake拉取同一个源端,此参数需要开启。
master_quorum = false

# http api interface. Users can use this api to monitor mongoshake.
# `curl 127.0.0.1:9100`.
# We also provide a restful tool named "mongoshake-stat" to
# print ack, lsn, checkpoint and qps information based on this api.
# usage: `./mongoshake-stat --port=9100`
# 全量和增量的restful监控端口,可以用curl查看内部监控metric统计情况。详见wiki。
full_sync.http_port = 9101
incr_sync.http_port = 9100
# profiling on net/http/profile
# profiling端口,用于查看内部go堆栈。
system_profile_port = 9200

# global log level: debug, info, warning, error. lower level message will be filter
log.level = info
# log directory. log and pid file will be stored into this file.
# if not set, default is "./logs/"
# log和pid文件的目录,如果不设置默认打到当前路径的logs目录。
log.dir =
# log file name.
# log文件名。
log.file = collector.log
# log flush enable. If set false, logs may not be print when exit. If
# set true, performance will be decreased extremely
# 设置log刷新,false表示包含缓存,如果true那么每条log都会直接刷屏,但对性能有影响;
# 反之,退出不一定能打印所有的log,调试时建议配置true。
log.flush = false

# sync mode: all/full/incr. default is incr.
# all means full synchronization + incremental synchronization.
# full means full synchronization only.
# incr means incremental synchronization only.
# 同步模式,all表示全量+增量同步,full表示全量同步,incr表示增量同步。
sync_mode = incr

# connect source mongodb, set username and password if enable authority. Please note: password shouldn't contain '@'.
# split by comma(,) if use multiple instance in one replica-set. E.g., mongodb://username1:password1@primaryA,secondaryB,secondaryC
# split by semicolon(;) if sharding enable. E.g., mongodb://username1:password1@primaryA,secondaryB,secondaryC;mongodb://username2:password2@primaryX,secondaryY,secondaryZ
# 源MongoDB连接串信息,逗号分隔同一个副本集内的结点,分号分隔分片sharding实例,免密模式
# 可以忽略“username:password@”,注意,密码里面不能含有'@'符号。
# 举例:
# 副本集:mongodb://username1:password1@primaryA,secondaryB,secondaryC
# 分片集:mongodb://username1:password1@primaryA,secondaryB,secondaryC;mongodb://username2:password2@primaryX,secondaryY,secondaryZ
mongo_urls = mongodb://username:password@127.0.0.1:20040,127.0.0.1:20041
# please fill the source config server url if source mongodb is sharding.
mongo_cs_url =
# please give at least one mongos address if source is sharding.
# 如果源端采用change stream拉取,这里还需要配置至少一个mongos的地址,多个mongos地址以逗号(,)分割
mongo_s_url =
# enable source ssl
mongo_ssl_root_ca_file =

# tunnel pipeline type. now we support rpc,file,kafka,mock,direct
# 通道模式。
tunnel = direct
# tunnel target resource url
# for rpc. this is remote receiver socket address
# for tcp. this is remote receiver socket address
# for file. this is the file path, for instance "data"
# for kafka. this is the topic and brokers address which split by comma, for
# instance: topic@brokers1,brokers2, default topic is "mongoshake"
# for mock. this is uesless
# for direct. this is target mongodb address which format is the same as `mongo_urls`. If
# the target is sharding, this should be the mongos address.
# direct模式用于直接写入MongoDB,其余模式用于一些分析,或者远距离传输场景,
# 注意,如果是非direct模式,需要通过receiver进行解析,具体参考FAQ文档。
# 此处配置通道的地址,格式与mongo_urls对齐。
tunnel.address = mongodb://127.0.0.1:20080
# the message format in the tunnel, used when tunnel is kafka.
# "raw": batched raw data format which has good performance but encoded so that users
# should parse it by receiver.
# "json": single oplog format by json.
# "bson": single oplog format by bson.
# 通道数据的类型,只用于kafka和file通道类型。
# raw是默认的类型,其采用聚合的模式进行写入和
# 读取,但是由于携带了一些控制信息,所以需要专门用receiver进行解析。
# json以json的格式写入kafka,便于用户直接读取。
# bson以bson二进制的格式写入kafka。
tunnel.message = raw
# how many partitions will be written, use some hash function in "incr_sync.shard_key".
# 如果目的端是kafka,最多启用多少个partition,最大不超过"incr_sync.worker"。默认1
tunnel.kafka.partition_number = 1
# tunnel json format, it'll only take effect in the case of tunnel.message = json
# and tunnel == kafka. Set canonical_extended_json if you want to use "Canonical
# Extended JSON Format", #559.
# 写入异构通道的json格式。如果希望使用Canonical Extended Json Format,则设置为
# canonical_extended_json
tunnel.json.format =
# if tunnel == driect or kafka and enable ssl
tunnel.mongo_ssl_root_ca_file =

# connect mode:
# primary: fetch data from primary.
# secondaryPreferred: fetch data from secondary if has, otherwise primary.(default)
# standalone: fetch data from given 1 node, no matter primary, secondary or hidden. This is only
# support when tunnel type is direct.
# 连接模式,primary表示从主上拉取,secondaryPreferred表示优先从secondary拉取(默认建议值),
# standalone表示从任意单个结点拉取。
mongo_connect_mode = secondaryPreferred

# filter db or collection namespace. at most one of these two parameters can be given.
# if the filter.namespace.black is not empty, the given namespace will be
# filtered while others namespace passed.
# if the filter.namespace.white is not empty, the given namespace will be
# passed while others filtered.
# all the namespace will be passed if no condition given.
# db and collection connected by the dot(.).
# different namespaces are split by the semicolon(;).
# filter: filterDbName1.filterCollectionName1;filterDbName2
# 黑白名单过滤,目前不支持正则,白名单表示通过的namespace,黑名单表示过滤的namespace,
# 不能同时指定。分号分割不同namespace,每个namespace可以是db,也可以是db.collection。
filter.namespace.black =
filter.namespace.white =
# some databases like "admin", "local", "mongoshake", "config", "system.views" are
# filtered, users can enable these database based on some special needs.
# different database are split by the semicolon(;).
# e.g., admin;mongoshake.
# pay attention: collection isn't support like "admin.xxx" except "system.views"
# 正常情况下,不建议配置该参数,但对于有些非常特殊的场景,用户可以启用admin,mongoshake等库的同步,
# 以分号分割,例如:admin;mongoshake。
filter.pass.special.db =
# only transfer oplog commands for syncing. represent
# by oplog.op are "i","d","u".
# DDL will be transferred if disable like create index, drop databse,
# transaction in mongodb 4.0.
# 是否需要开启DDL同步,true表示开启,源是sharding暂时不支持开启。
# 如果目的端是sharding,暂时不支持applyOps命令,包括事务。
filter.ddl_enable = false
# filter oplog gid if enabled.
# 如果MongoDB启用了gid,但是目的端MongoDB不支持gid导致同步会失败,可以启用gid过滤,将会去掉gid字段。
# 谨慎建议开启,shake本身性能受损很大。
filter.oplog.gids = false

# checkpoint info, used in resuming from break point.
# checkpoint存储信息,用于支持断点续传。
# context.storage.url is used to mark the checkpoint store database. E.g., mongodb://127.0.0.1:20070
# if not set, checkpoint will be written into source mongodb(db=mongoshake)
# checkpoint的具体写入的MongoDB地址,如果不配置,对于副本集和分片集群都将写入源库(db=mongoshake)
# 2.4版本以后不需要配置为源端cs的地址。
checkpoint.storage.url =
# checkpoint db's name.
# checkpoint存储的db的名字
checkpoint.storage.db = mongoshake
# checkpoint collection's name.
# checkpoint存储的表的名字,如果启动多个mongoshake拉取同一个源可以修改这个表名以防止冲突。
checkpoint.storage.collection = ckpt_default
# set if enable ssl
checkpoint.storage.url.mongo_ssl_root_ca_file =
# real checkpoint: the fetching oplog position.
# pay attention: this is UTC time which is 8 hours latter than CST time. this
# variable will only be used when checkpoint is not exist.
# 本次开始拉取的位置,如果checkpoint已经存在(位于上述存储位置)则该参数无效,
# 如果需要强制该位置开始拉取,需要先删除原来的checkpoint,详见FAQ。
# 若checkpoint不存在,且该值为1970-01-01T00:00:00Z,则会拉取源端现有的所有oplog。
# 若checkpoint不存在,且该值不为1970-01-01T00:00:00Z,则会先检查源端oplog最老的时间是否
# 大于给定的时间,如果是则会直接报错退出。
checkpoint.start_position = 1970-01-01T00:00:00Z

# transform from source db or collection namespace to dest db or collection namespace.
# at most one of these two parameters can be given.
# transform: fromDbName1.fromCollectionName1:toDbName1.toCollectionName1;fromDbName2:toDbName2
# 转换命名空间,比如a.b同步后变成c.d,谨慎建议开启,比较耗性能。
transform.namespace =

# --------------------------- full sync configuration ---------------------------
# the number of collection concurrence
# 并发最大拉取的表个数,例如,6表示同一时刻shake最多拉取6个表。
full_sync.reader.collection_parallel = 6
# the number of document writer thread in each collection.
# 同一个表内并发写的线程数,例如,8表示对于同一个表,将会有8个写线程进行并发写入。
full_sync.reader.write_document_parallel = 8
# number of documents in a batch insert in a document concurrence
# 目的端写入的batch大小,例如,128表示一个线程将会一次聚合128个文档然后再写入。
full_sync.reader.document_batch_size = 128
# number of documents in a batch in fetch from source db
# 源端拉取batch中最大条数
full_sync.reader.fetch_batch_size = 8192
# max number of fetching thread per table. default is 1
# 单个表最大拉取的线程数,默认是单线程拉取。需要具备splitVector权限。
# 注意:对单个表来说,仅支持索引对应的value是同种类型,如果有不同类型请勿启用该配置项!
full_sync.reader.parallel_thread = 1
# the parallel query index if set full_sync.reader.parallel_thread. index should only has
# 1 field.
# 如果设置了full_sync.reader.parallel_thread,还需要设置该参数,并行拉取所扫描的index,value
# 必须是同种类型。对于副本集,建议设置_id;对于集群版,建议设置shard_key。key只能有1个field。
full_sync.reader.parallel_index = _id

# drop the same name of collection in dest mongodb in full synchronization
# 同步时如果目的库存在,是否先删除目的库再进行同步,true表示先删除再同步,false表示不删除。
full_sync.collection_exist_drop = true

# create index option.
# none: do not create indexes.
# foreground: create indexes when data sync finish in full sync stage.
# background: create indexes when starting.
# 全量期间数据同步完毕后,是否需要创建索引,none表示不创建,foreground表示创建前台索引,
# background表示创建后台索引。
full_sync.create_index = none

# convert insert to update when duplicate key found
# 如果_id存在在目的库,是否将insert语句修改为update语句。
full_sync.executor.insert_on_dup_update = false
# filter orphan document for source type is sharding.
# 源端是sharding,是否需要过滤orphan文档
full_sync.executor.filter.orphan_document = false
# enable majority write in full sync.
# the performance will degrade if enable.
# 全量阶段写入端是否启用majority write
full_sync.executor.majority_enable = false

# --------------------------- incrmental sync configuration ---------------------------
# fetch method:
# oplog: fetch oplog from source mongodb (default)
# change_stream: use change to receive change event from source mongodb, support MongoDB >= 4.0.
# we recommand to use change_stream if possible.
incr_sync.mongo_fetch_method = oplog

# After the document is updated, the fields that only need to be updated are set to false,
# and the contents of all documents are set to true
# 更新文档后,只需要更新的字段则设为false,需要全部文档内容则设为true
# 只在mongo_fetch_method = change_stream 模式下生效,且性能有所下降
incr_sync.change_stream.watch_full_document = false

# global id. used in active-active replication.
# this parameter is not supported on current open-source version.
# gid用于双活防止环形复制,目前只用于阿里云云上MongoDB,如果是阿里云云上实例互相同步
# 希望开启gid,请联系阿里云售后,sharding的有多个gid请以分号(;)分隔。
incr_sync.oplog.gids =

# distribute data to different worker by hash key to run in parallel.
# [auto] 		decide by if there has unique index in collections.
# 		 		use `collection` if has unique index otherwise use `id`.
# [id] 			shard by ObjectId. handle oplogs in sequence by unique _id
# [collection] 	shard by ns. handle oplogs in sequence by unique ns
# hash的方式,id表示按文档hash,collection表示按表hash,auto表示自动选择hash类型。
# 如果没有索引建议选择id达到非常高的同步性能,反之请选择collection。
incr_sync.shard_key = collection
# if shard_key is collection, and users want to improve performance when some collections
# do not have unique key.
# 对于按collection哈希,如果某些表不具有唯一索引,则可以设置按_id哈希以提高并发度。
# 用户需要确认该表不会创建唯一索引,一旦检测发现存在唯一索引,则会立刻crash退出。
# 例如,db1.collection1;db2.collection2,不支持仅指定db
incr_sync.shard_by_object_id_whitelist =

# oplog transmit worker concurrent
# if the source is sharding, worker number must equal to shard numbers.
# 内部发送(写目的DB)的worker数目,如果机器性能足够,可以提高worker个数。
incr_sync.worker = 8

# how many writing threads will be used in one worker.
# 对于目的端是kafka等非direct tunnel,启用多少个序列化线程,必须为"incr_sync.worker"的倍数。
# 默认为"incr_sync.worker"的值。
incr_sync.tunnel.write_thread = 8

# set the sync delay just like mongodb secondary slaveDelay parameter. unit second.
# 设置目的端的延迟,比如延迟源端20分钟,类似MongoDB本身主从同步slaveDelay参数,单位:秒
# 0表示不启用
incr_sync.target_delay = 0

# memory queue configuration, plz visit FAQ document to see more details.
# do not modify these variables if the performance and resource usage can
# meet your needs.
# 内部队列的配置参数,如果目前性能足够不建议修改,详细信息参考FAQ。
# batch_queue_size:每个worker线程的队列长度,worker线程从此队列取任务
# batching_max_size:一次分发给worker的任务最多包含多少个文档
# buffer_capacity:PendingQueue队列中一个buffer至少包含的文档个数,进行序列化
incr_sync.worker.batch_queue_size = 64
incr_sync.adaptive.batching_max_size = 1024
incr_sync.fetcher.buffer_capacity = 256
incr_sync.reader.fetch_batch_size = 8192

# --- direct tunnel only begin ---
# if tunnel type is direct, all the below variable should be set
# 下列参数仅用于tunnel为direct的情况。

# oplog changes to Insert while Update found non-exist (_id or unique-index)
# 如果_id不存在在目的库,是否将update语句修改为insert语句。
incr_sync.executor.upsert = false
# oplog changes to Update while Insert found duplicated key (_id or unique-index)
# 如果_id存在在目的库,是否将insert语句修改为update语句。
incr_sync.executor.insert_on_dup_update = false
# options:db,none
# db. write duplicated logs to mongoshake_conflict
# 如果写入存在冲突,记录冲突的文档。选项:db, none
# db:冲突写到目的DB的mongshake_conflict库中
incr_sync.conflict_write_to = none

# enable majority write in incrmental sync.
# the performance will degrade if enable.
# 增量阶段写入端是否启用majority write
incr_sync.executor.majority_enable = false

# --- direct tunnel only end ---

# 特殊字段,标识源端类型,默认为空。阿里云MongoDB serverless集群请配置aliyun_serverless
special.source.db.flag =

不带注释版本

$ cat collector.conf |grep -v "#"

# 当前配置文件的版本号,请不要修改该值。
conf.version = 10

# --------------------------- global configuration ---------------------------
# id用于输出pid文件等信息。
id = mongoshake

# 如果开启主备mongoshake拉取同一个源端,此参数需要开启。
master_quorum = false

# 全量和增量的restful监控端口,可以用curl查看内部监控metric统计情况。详见wiki。mongoshake-stat
full_sync.http_port = 9101
incr_sync.http_port = 9100
# profiling端口,用于查看内部go堆栈。
system_profile_port = 9200

# global log level: debug, info, warning, error. lower level message will be filterlog.level = info
# log和pid文件的目录,如果不设置默认打到当前路径的logs目录。
log.dir = /data/storage/mongoshake
# log文件名。
log.file = collector.log
# 设置log刷新,false表示包含缓存,如果true那么每条log都会直接刷屏,但对性能有影响;
# 反之,退出不一定能打印所有的log,调试时建议配置true。
log.flush = false

# 同步模式,all表示全量+增量同步,full表示全量同步,incr表示增量同步。
sync_mode = all


mongo_urls = mongodb://username:password@127.0.0.1:20040,127.0.0.1:20041
mongo_cs_url =
mongo_s_url =
mongo_ssl_root_ca_file =

tunnel = direct
tunnel.address = mongodb://127.0.0.1:20080
tunnel.message = raw
tunnel.kafka.partition_number = 1
tunnel.json.format =
tunnel.mongo_ssl_root_ca_file =

mongo_connect_mode = secondaryPreferred

filter.namespace.black =
filter.namespace.white =
filter.pass.special.db =
filter.ddl_enable = false
filter.oplog.gids = false

checkpoint.storage.url =
checkpoint.storage.db = mongoshake
checkpoint.storage.collection = ckpt_default
checkpoint.storage.url.mongo_ssl_root_ca_file =
checkpoint.start_position = 1970-01-01T00:00:00Z

transform.namespace =

full_sync.reader.collection_parallel = 6
full_sync.reader.write_document_parallel = 8
full_sync.reader.document_batch_size = 128
full_sync.reader.fetch_batch_size = 8192
full_sync.reader.parallel_thread = 1
full_sync.reader.parallel_index = _id

full_sync.collection_exist_drop = true

full_sync.create_index = none

full_sync.executor.insert_on_dup_update = false
full_sync.executor.filter.orphan_document = false
full_sync.executor.majority_enable = false

incr_sync.mongo_fetch_method = oplog

incr_sync.change_stream.watch_full_document = false

incr_sync.oplog.gids =

incr_sync.shard_key = collection
incr_sync.shard_by_object_id_whitelist =

incr_sync.worker = 8

incr_sync.tunnel.write_thread = 8

incr_sync.target_delay = 0

incr_sync.worker.batch_queue_size = 64
incr_sync.adaptive.batching_max_size = 1024
incr_sync.fetcher.buffer_capacity = 256
incr_sync.reader.fetch_batch_size = 8192


incr_sync.executor.upsert = false
incr_sync.executor.insert_on_dup_update = false
incr_sync.conflict_write_to = none

incr_sync.executor.majority_enable = false


special.source.db.flag =

 

  在bin目录下执行:./collector -conf=collector.conf,log会写入目录log.dir,文件名为log.file,如果希望log打印的屏幕,请额外添加-verbose

3 运行

参考

原理参考:GitHub - alibaba/MongoShake: MongoShake is a universal data replication platform based on MongoDB's oplog. Redundant replication and active-active replication are two most important functions. 基于mongodb oplog的集群复制工具,可以满足迁移和同步的需求,进一步实现灾备和多活功能。

安装使用参考

第一次使用,如何进行配置? · alibaba/MongoShake Wiki · GitHub

常见问题
常见问题&FAQ · alibaba/MongoShake Wiki · GitHub

### MongoShake 使用指南 #### 一、简介 MongoShake 是一款用于 MongoDB 数据库的数据同步工具,支持多种部署模式下的数据复制需求。无论是单机环境还是复杂的分布式架构,该工具均能提供稳定高效的服务[^1]。 #### 二、安装过程 为了开始使用此工具,在本地计算机上获取最新版本的源码十分必要。通过 Git 命令行客户端完成这一操作: ```bash git clone https://github.com/alibaba/MongoShake.git cd MongoShake ``` 接着按照官方文档指示编译程序文件,确保所有依赖项都已正确加载并解决可能出现的问题,比如遇到模块找不到的情况时需确认 Go 环境变量设置无误以及项目内部包路径是否匹配当前 GOPATH 结构等[^3]。 #### 三、配置说明 进入 `conf` 文件夹查看默认模板,并依据实际场景调整参数选项。主要关注以下几个方面: - **source** 和 **target**: 明确指出参与同步作业两端的具体实例信息; - 当源端为副本集群时推荐选取次级节点作为读取入口以减轻主服务器负担;对于分片集合,则应针对每一个独立片段建立相应的连接关系; - 对于目标侧而言,允许存在多台路由代理设备共同承担写入任务从而保障系统的可靠性与性能表现[^4]。 #### 四、运行方式 启动前务必验证各项设定均已妥善安排完毕。通常情况下只需简单调用可执行文件即可触发整个流程: ```bash ./bin/mongoshake -f conf/tunnel.conf ``` 上述指令中的 `-f` 参数后面跟的是之前编辑好的配置档名称,请根据实际情况替换相应路径。 #### 五、注意事项 在整个过程中可能会碰到各种各样的挑战,例如网络延迟过高影响传输效率等问题都需要及时排查处理。另外值得注意的一点是在大规模生产环境中应用此类技术方案前最好先进行全面的功能性和稳定性测试以规避潜在风险[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DBA之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值