对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

连接两个自托管集群

mongosync 实用程序在MongoDB集群之间创建连接。mongosync 可以连接到以下任何集群:

本页提供使用MongoDB Mongosync 连接自管理集群的说明。

注意

为获得最佳性能,请在迁移前将源集群和目标集群升级到最新的MongoDB Server补丁发布。 有关更多信息,请参阅升级到MongoDB的最新自我管理补丁版本。

mongosync 使用MongoDB URI 连接string连接集群:

  • SRV 连接方案的形式为:

    mongodb+srv://[username:password@][host.domain.TLD][:port][/defaultauthdb][?options]
  • 标准 URI 连接方案的形式如下:

    mongodb://[username:password@]host1[:port1][,...hostN[:portN]][/[defaultauthdb][?options]]

Specify the hostnames of the mongod instances the same way that they are listed in your replica set configuration.

For sharded clusters, specify the hostnames of the mongos instances instead of the mongod instances.

注意

mongosync does not require the replicaSet option.

mongosync requires the primary read preference to connect to the source and destination clusters. For more information, see Read Preference Options.

如果源集群或目标集群需要身份验证,则必须在调用mongosync时提供正确的档案。

mongosync连接字符串中指定的用户必须对源集群和目标集群具有所需的权限。权限因您的环境以及您是否要使用反向同步而异。

自我托管权限包括:

有关服务器角色的详细信息,请参阅:自管理部署中基于角色的访问控制。

To update user permissions, see: grantRolesToUser.

The mongosync utility can be hosted on its own hardware close to either the source or destination cluster. It does not have to be hosted on the same server as one of the mongod or mongos instances in the cluster. This flexibility allows you to push, or pull, data to the destination cluster with minimal impact on the mongod or mongos instances running there.

mongosync连接时,它处于IDLE状态。 您必须发出启动命令才能开始同步。

源集群cluster0托管在以下服务器和端口上:

  • clusterOne01.fancyCorp.com:20020

  • clusterOne02.fancyCorp.com:20020

  • clusterOne03.fancyCorp.com:20020

目标集群cluster1托管在以下服务器和端口上:

  • clusterTwo01.fancyCorp.com:20020

  • clusterTwo02.fancyCorp.com:20020

  • clusterTwo03.fancyCorp.com:20020

每个集群上都配置了一个管理用户clusterAdmin ,密码为superSecret

通用连接字符串格式为:

mongodb://<user>:<password>@<ip-address>:<port>,<ip-address>:<port>,<ip-address>:<port>

使用收集的连接信息为cluster0cluster1创建连接字符串:

cluster0:
mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020
cluster1:
mongodb://clusterAdmin:superSecret@clusterTwo01.fancyCorp.com:20020,clusterTwo02.fancyCorp.com:20020,clusterTwo03.fancyCorp.com:20020

下面的mongosync命令布局已修改以进行显示。 要使用mongosynccluster0连接到cluster1 ,请在一行中输入以下命令:

mongosync \
--cluster0 "mongodb://clusterAdmin:superSecret@clusterOne01.fancyCorp.com:20020,clusterOne02.fancyCorp.com:20020,clusterOne03.fancyCorp.com:20020" \
--cluster1 "mongodb://clusterAdmin:superSecret@clusterTwo01.fancyCorp.com:20020,clusterTwo02.fancyCorp.com:20020,clusterTwo03.fancyCorp.com:20020"

You can also use mongodb+srv connection strings with mongosync. You do not need to add the tls=true option to a mongodb+srv connection string. For example:

mongosync \
--cluster0 "mongodb+srv://clusterAdmin:superSecret@clusterOne01.fancyCorp.com/" \
--cluster1 "mongodb+srv://clusterAdmin:superSecret@clusterTwo01.fancyCorp.com/"

有关mongodb+srv连接字符串的更多详细信息,请参阅SRV 连接格式。