Convert Sharded Cluster to Replica Set将分片群集转换为副本集

On this page本页内容

This tutorial describes the process for converting a sharded cluster to a non-sharded replica set. 本教程介绍将分片集群转换为非分片副本集的过程。To convert a replica set into a sharded cluster Convert a Replica Set to a Sharded Cluster. 要将副本集转换为分片群集,请将副本集转化为分片群集See the Sharding documentation for more information on sharded clusters.有关分片集群的更多信息,请参阅分片文档。

Convert a Cluster with a Single Shard into a Replica Set将具有单个分片的群集转换为副本集

In the case of a sharded cluster with only one shard, that shard contains the full data set. 对于只有一个分片的分片集群,该分片包含完整的数据集。Use the following procedure to convert that cluster into a non-sharded replica set:使用以下过程将该群集转换为非分片副本集

  1. Reconfigure the application to connect to the primary member of the replica set hosting the single shard that system will be the new replica set.重新配置应用程序以连接到承载单个分片的副本集的主要成员,该系统将成为新的副本集。
  2. Remove the --shardsvr option from your mongod.mongod中删除--shardsvr选项。

    Tip提示

    Changing the --shardsvr option will change the port that mongod listens for incoming connections on.更改--shardsvr选项将更改mongod侦听传入连接的端口。

The single-shard cluster is now a non-sharded replica set that will accept read and write operations on the data set.单分片集群现在是一个非分片副本集,将接受对数据集的读写操作。

You may now decommission the remaining sharding infrastructure.您现在可以停止使用剩余的分片基础设施。

Convert a Sharded Cluster into a Replica Set将分片群集转换为副本集

Use the following procedure to transition from a sharded cluster with more than one shard to an entirely new replica set.使用以下过程从具有多个分片的分片集群过渡到全新的副本集

  1. With the sharded cluster running, deploy a new replica set in addition to your sharded cluster. 在分片集群运行的情况下,除了您的分片集群之外,还要部署一个新的副本集The replica set must have sufficient capacity to hold all of the data files from all of the current shards combined. 副本集必须有足够的容量来保存来自所有当前分片的所有数据文件。Do not configure the application to connect to the new replica set until the data transfer is complete.在数据传输完成之前,不要将应用程序配置为连接到新副本集。
  2. Stop all writes to the sharded cluster. 停止对分片群集的所有写入。You may reconfigure your application or stop all mongos instances. 您可以重新配置应用程序或停止所有mongos实例。If you stop all mongos instances, the applications will not be able to read from the database. 如果停止所有mongos实例,应用程序将无法读取数据库。If you stop all mongos instances, start a temporary mongos instance on that applications cannot access for the data migration procedure.如果停止所有mongos实例,请在应用程序无法访问的数据迁移过程上启动一个临时mongos示例。
  3. Use mongodump and mongorestore to migrate the data from the mongos instance to the new replica set.使用mongodumpmongorestore将数据从mongos实例迁移到新的副本集

    Note注意

    Not all collections on all databases are necessarily sharded. 并非所有数据库上的所有集合都必须进行分片。Do not solely migrate the sharded collections. 不要只迁移分片集合。Ensure that all databases and all collections migrate correctly.确保所有数据库和所有集合正确迁移。

  4. Reconfigure the application to use the non-sharded replica set instead of the mongos instance.重新配置应用程序以使用非分片副本集,而不是mongos实例。

The application will now use the un-sharded replica set for reads and writes. 应用程序现在将使用未分片副本集进行读取和写入。You may now decommission the remaining unused sharded cluster infrastructure.您现在可以停用剩余的未使用的分片群集基础结构。

←  Back Up Cluster MetadataConvert a Replica Set to a Sharded Cluster →