安装部署
解压
建议部署在离目标端近的地方,比如部署再目标端本地
tar -zxvf mongo-shake-v2.8.1.tgz
配置
同构环境下主要参数

启动
执行下述命令启动同步任务,并打印日志信息,-verbose 0表示将日志打印到文件,在后台运行
nohup ./collector.linux -conf=collector.conf -verbose 0 &
全量
为防止主库oplog不足,提前调整oplog大小
db.adminCommand({
replSetResizeOplog:1,size:1000})
观察打印日志信息,如下表示全量完成
10GB数据限速8000TPS,耗时1.5H
[09:38:57 CST 2019/06/20] [INFO] (mongoshake/collector.(*ReplicationCoordinator).Run:80) finish full sync, start incr sync with timestamp: fullBeginTs[1560994443], fullFinishTs[1560994737]
重新全量同步
如需重新进行全量同步,只需要停止同步进程,删除存储checkpoint的表,重新启动同步进程即可
use mongoshake
db.ckpt_default.drop()
问题
全量同步时,报如下错误,源端环境为3.6.3,存在bug,通过小版本升级至3.6.23解决该问题
bug连接:https://jira.mongodb.org/browse/SERVER-34810
[2022/11/26 17:47:46 CST] [CRIT] splitter reader[DocumentReader id[0], src[mongodb://admin:***@192.168.62.25:27017,192.168.62.26:27017,192.168.62.27:27017] ns[{
paymentdb test}] query[map[]]] get next document failed: (CursorNotFound) cursor id 75188853290 not found
如果还有什么问题可以直接到入下网址向作者反应
https://github.com/alibaba/MongoShake/issues
如何监控和管理MongoShake的运行状态?
MongoDB一共从2个方面提供监控,全量和增量,分为2个端口。全量部分的监控是从2.4.1版本才开放的,增量部分监控从1.0.0就开放了。
注意:通过sentinel接口的相应修改都不会持久化,也就是说通过sentinel接口修改的变量在MongoShake发生重启后都会清空,需要重新配置。持久化功能后面版本会做掉,敬请期待。
如何查看监控?
直接curl对应的端口就行,例如,在配置文件中有一个端口的配置,v2.4.1版本以前是http_profile(默认值是9100),v2.4.1开始分拆为2个,full_sync.http_port(默认9101)表示全量的端口,incr_sync.http_port(默认9100)是增量的端口。直接调用curl命令就能看到(加上python -m json可以更加清晰):
vinllen@~/code/MongoShake$ curl -s http://127.0.0.1:9101
[{
"Uri":"/conf","Method":"GET"},{
"Uri":"/progress","Method":"GET"},...]
vinllen@~/code/MongoShake$ curl -s http://127.0.0.1:9101 | python -m json.tool
[
{
"Method": "GET",
"Uri": "/conf"
},
{
"Method": "GET",
"Uri": "/progress"
}
.... // 省略
]
上面返回的有conf和progress,可以分别再curl这个对应的接口,比如conf表示的是配置文件信息:
vinllen@~/code/MongoShake$ curl -s http://127.0.0.1:9101/conf | python -m json.tool
{
"CheckpointInterval": 5000,
"CheckpointStartPosition": 1585220856,
"CheckpointStorage": "database",
"CheckpointStorageCollection": "ckpt_default",
"CheckpointStorageDb": "mongoshake",
"CheckpointStorageUrl": "mongodb://xxx:31773,xxx:31772,xxx:31771",
"ConfVersion": 1,
"FilterDDLEnable": false,
"FilterNamespaceBlack": null,
"FilterNamespaceWhite": null,
"FilterPassSpecialDb": [],
"FullSyncCollectionDrop": true,
"FullSyncCreateIndex": "foreground",
"FullSyncExecutorDebug": false,
"FullSyncExecutorFilterOrphanDocument": false,
"FullSyncExecutorInsertOnDupUpdate": false,
"FullSyncExecutorMajorityEnable": false,
"FullSyncHTTPListenPort": 9100,
"FullSyncReaderCollectionParallel": 6,
"FullSyncReaderDocumentBatchSize": 128,
"FullSyncReaderOplogStoreDisk": false,
"FullSyncReaderOplogStoreDiskMaxSize": 256000,
"FullSyncReaderReadDocumentCount": 0,
"FullSyncReaderWriteDocumentParallel": 8,
"HTTPListenPort": 9100,
"Id"


3010

被折叠的 条评论
为什么被折叠?



