首页 > 数据库 >MongoDB集群同步

MongoDB集群同步

时间:2024-07-12 20:56:56浏览次数:4  
标签:00 同步 04 MongoDB 08 2024 集群 20000 message

实现 MongoDB Cluster-to-Cluster 即集群同步的工具是:mongosync
详情可参考如下官方文档:
https://www.mongodb.com/zh-cn/docs/cluster-to-cluster-sync/current/quickstart/
以上这个地址的文档一看就是机器翻译的,可能有不恰当的地方,但基本可参考使用。
以下是本次在某项目地配置集群同步的简要步骤,可参考使用。

一、首先在目的集群安装同步工具mongosync

本次使用的是版本匹配的1.5.0版本:
https://fastdl.mongodb.org/tools/mongosync/mongosync-rhel80-x86_64-1.5.0.tgz
以下是我习惯使用的安装脚本:

KDR=/u01
cd ${KDR}
TGZ=mongosync-rhel80-x86_64-1.5.0
#cp_unzip_chown_ln:
cp /u01/nfs/MongoDB/${TGZ}.tgz .
tar zxvf ${TGZ}.tgz
chown -R mongod:mongod ${TGZ}
ln -s ${KDR}/${TGZ}/bin/* /usr/local/bin/

二、集群规划信息配置

在/etc/hosts文件追加host定义(mongodb25~33),方便用于MongoDB集群同步脚本调用[以下代码已做脱敏处理]

cat >> /etc/hosts << EOF
# 生产集群
2409:xx:1a mongodb25
2409:xx:1b mongodb26
2409:xx:1c mongodb27
# 容灾集群
2409:xx:1d mongodb28
2409:xx:1e mongodb29
2409:xx:1f mongodb30
# 历史数据集群
2409:xx:20 mongodb31
2409:xx:21 mongodb32
2409:xx:22 mongodb33
EOF

三、mongosync 执行

LOGFILE=mongosync.liking.`date +%Y%m%d-%H:%M`.log
mongosync \
    --logPath /var/log/mongosync \
    --cluster0 mongodb://admin:passwd@mongodb28:20000,mongodb29:20000,mongodb30:20000/?authSource=admin \
    --cluster1 mongodb://admin:passwd@mongodb31:20000,mongodb32:20000,mongodb33:20000/?authSource=admin \
    --verbosity INFO > ${LOGFILE} 2>&1 &

启用同步服务后,可以在日志目录/var/log/mongosync查看日志信息。

四、POST 同步命令 start

■ 同步整个集群【本次使用】

curl "http://localhost:27182/api/v1/start" -XPOST --data '{
  "source": "cluster0",
  "destination": "cluster1"
}'

■ 同步指定的数据库

curl "http://localhost:27182/api/v1/start" -XPOST --data '{
  "source": "cluster0",
  "destination": "cluster1"
  "includeNameSpaces": [
    {
      "database": "flowtest"
    }
  ]
}'

■ 同步指定的集合

curl "http://localhost:27182/api/v1/start" -XPOST --data '{
  "source": "cluster0",
  "destination": "cluster1",
  "includeNameSpaces": [
    {
      "database": "flowtest",
      "collections": [ "activityConfiguration", "history_task", "processConfiguration", "processDataObj",  "snapshotResource" ]
    }
  ]
}'

■ 同步时的运维操作

curl "http://localhost:27182/api/v1/progress" -XGET
curl "http://localhost:27182/api/v1/pause" -XPOST --data '{}'
curl "http://localhost:27182/api/v1/resume" -XPOST --data '{}'

五、全量同步日志1

本次全量同步的数据规模如下:

[mongos] testdb> show databases
admin     252.00 KiB
config     35.56 MiB
flowtest  624.74 GiB

同步开始阶段的重要信息如下:

{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","uri":"/api/v1/start","method":"POST","body":"{\n \"source\": \"cluster0\",\n  \"destination\": \"cluster1\"\n}","clientIP":"::1","traceID":"fec8eb4b-8123-4a33-a1a5-d6cf57b431ea","time":"2024-04-18T16:47:49.511390067+08:00","message":"received request"}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","source":"cluster0","destination":"cluster1","reversible":false,"enableUserWriteBlocking":false,"time":"2024-04-18T16:47:49.511783755+08:00","message":"Start handlercalled"}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","sourceURI":"mongodb28:20000,mongodb29:20000,mongodb30:20000","dstURI":"mongodb31:20000,mongodb32:20000,mongodb33:20000","time":"2024-04-18T16:47:49.511812312+08:00","message":"Creating clients and connecting to clusters."}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","clusterType":"src","operation description":"Pinging deployment at mongodb://admin:<REDACTED>@mongodb28:20000,mongodb29:20000,mongodb30:20000/?authSource=admin to establish initial connection.","attemptNumber":0,"durationSoFarSecs":0,"durationLimitSecs":10,"time":"2024-04-18T16:47:49.512143259+08:00","message":"Trying operation."}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","clusterType":"dst","operation description":"Pinging deployment at mongodb://admin:<REDACTED>@mongodb31:20000,mongodb32:20000,mongodb33:20000/?authSource=admin to establish initial connection.","attemptNumber":0,"durationSoFarSecs":0,"durationLimitSecs":10,"time":"2024-04-18T16:47:49.530184069+08:00","message":"Trying operation."}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","time":"2024-04-18T16:47:49.545274189+08:00","message":"Successfully initialized source and destination clients"}

全量同步完毕阶段的重要日志信息如下:

{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","componentName":"Collection Copy","time":"2024-04-18T20:29:55.31864523+08:00","message":"All Collection Copy components have stopped."}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","componentName":"Collection Copy","time":"2024-04-18T20:29:55.318660079+08:00","message":"Completed writing 6487 / 6487 partitions to destination cluster"}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","componentName":"CHECKPOINT","totalBytes":2717579843528,"copiedBytes":2717920929608,"time":"2024-04-18T20:29:55.318684889+08:00","message":"Finished collection copy phase."}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","componentName":"CHECKPOINT","time":"2024-04-18T20:29:55.330386515+08:00","message":"Waiting for collection copy phase to complete."}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","componentName":"CHECKPOINT","time":"2024-04-18T20:29:55.351147335+08:00","message":"Running change event application phase."}
{"level":"info","serverID":"bb927128","mongosyncID":"coordinator","componentName":"Change Event Application","time":"2024-04-18T20:29:55.365007664+08:00","message":"Starting index checker service which runs a cycle every 60 seconds."}

以上日志可见:
620G数据,同步耗时3.5小时左右,性能比之前测试稍慢。
再次印证了mongodb本身的压缩算法较好,实际fs层面的数据大小如下:

"totalBytes":2717579843528,"copiedBytes":2717920929608,"time":"2024-04-18T20:29:55.318684889+08:00","message":"Finished collection copy phase."

六、全量同步日志2

当晚实际生产集群全量同步的数据规模如下:

flowtest            684.20 GiB
{"estimatedTotalBytes":2972595055214,"estimatedCopiedBytes":2973012240862}

实际耗时2h55m,可见同样硬件、网络环境夜间性能稍好。

七、思考

通过以上实践,显而易见,MongoDB集群同步技术使得我们后续迁移数据库变得轻而易举,实际割接时间可控制在几分钟以内。

标签:00,同步,04,MongoDB,08,2024,集群,20000,message
From: https://www.cnblogs.com/likingzi/p/18299389

相关文章

  • 0基础_永磁同步电机FOC(矢量控制)实践快速入门(一)——通过DSP28335配置SPI与AD2S1210通信
    AD2S1210.cADSP28335配置SPA模块与AD2S1210通信读取旋转变压器反馈的位置、速度信息欢迎大家进群领取电机控制,嵌入式学习资料!程序文件也在群里哦目录文章目录前言一、位置角是什么,为什么要获取位置角?二、如何获取位置角?三、AD2S1210介绍四、如何通过AD2S1210进行旋......
  • Redis的哨兵和集群实现高可用
    一个典型的高可用Redis集群示例配置1个主服务器2-3个从服务器3-5个哨兵哨兵和集群就是为了高可用哨兵哨兵的功能:监听和故障转移(1)客户端可以从哨兵获得集群的状态。(2)当主服务器断开,哨兵可以进行选举主服务器。哨兵的工作流程在配置中,设置master的ip和端口创建maste......
  • 科普 | 3分钟读懂高精度时间同步
    通过上一期的内容我们知道北京时间作为我们国家的标准时间,是由中国科学院国家授时中心产生、保持和发播的。中国科学院国家授时中心位于陕西西安临潼,那北京时间诞生于这里,是怎么做到让全国人民都用上北京时间呢,大家又是通过什么手段和北京时间实现同步的呢?看完本期内容,相信你......
  • 编译安装Kubernetes 1.29 高可用集群(9)--Harbor私有仓库部署
    1.环境说明操作系统:openEuler22.03软件版本:harbor2.10.32.Harbor软件安装2.1安装前准备#systemctldisablefirewalld.service#systemctlstopfirewalld.service#sed-i's/SELINUX=enforcing/SELINUX=disabled/'/etc/selinux/config#setenforce0#hostnamec......
  • 状态同步和帧同步原理细节
    状态同步(StateSynchronization)状态同步是一种基于服务器的同步机制,其中服务器周期性地将游戏状态(如玩家位置、物体状态等)发送给客户端,客户端根据接收到的状态进行更新。原理服务器状态更新:服务器持续更新游戏状态,并以固定时间间隔将状态发送给所有客户端。客户端状态接......
  • Linux设备驱动器 之二 线程同步第二篇
    Linux设备驱动器之二线程同步第二篇mutex数据结构LinuxAPIs在Linux驱动器中的应用NXPfreescale系列QSPI驱动器变量定义初始化存取数据semaphore数据结构LinuxAPIs在Linux驱动器中的应用ELAN的Uxxx系列驱动器变量定义初始化同步操作mutex数据结构stru......
  • 软件系统的架构演进以及集群和分布式
    一、单体架构:将四个模块ABCD放到一个项目中,功能模块不进行拆分,项目整体搭建集群叫做多机单体架构,项目不搭建集群叫单机单体架构。                 单体架构的优点:简单:开发部署都很方便,小型项目首选单体架构的缺点:......
  • 在linux服务器上搭建slurm集群部署
    在Linux服务器上搭建Slurm集群部署是一个涉及多个步骤和组件配置的过程。Slurm是一个面向Linux和Unix的开源作业调度程序,广泛用于高性能计算环境。一、环境准备选择服务器和硬件设备:选择合适的服务器和硬件设备,建议选用多核心、大内存、高速硬盘的服务器以满足高性能计算的需求......
  • StarRocks跨集群迁移最佳实践|得物技术
    一、引言2024年之前,DBA维护的StarRocks集群存在在用低版本多、稳定性受组件bug影响大的问题,给日常运维带来一定压力,版本升级迫在眉睫。于是,我们在今年年初安排了针对2.5以下版本升级2.5.13的专项。这里和大家分享下,针对因版本兼容问题而不能原地升级的场景下,进行跨集群升级......
  • Kubernetes高可用集群二进制离线部署(Runtime Docker)
    Kubernetes高可用集群二进制部署(RuntimeDocker)Kubernetes(简称为:k8s)是Google在2014年6月开源的一个容器集群管理系统,使用Go语言开发,用于管理云平台中多个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单并且高效,Kubernetes提供了资源调度、部署管理、服务......