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

On this page本页内容

Overview概述

This tutorial converts a single three-member replica set to a sharded cluster with two shards. 本教程将单个三成员副本集转换为具有两个分片的分片集群。Each shard is an independent three-member replica set. 每个分片都是一个独立的三成员副本集。This tutorial is specific to MongoDB 5.0. For other versions of MongoDB, refer to the corresponding version of the MongoDB Manual.本教程特定于MongoDB 5.0。有关MongoDB的其他版本,请参阅相应版本的MongoDB手册。

The procedure is as follows:程序如下:

  1. Create the initial three-member replica set and insert data into a collection. 创建初始的三成员副本集,并将数据插入到集合中。See Set Up Initial Replica Set.请参见设置初始副本集
  2. Start the config servers and a mongos. 启动配置服务器和mongosSee Deploy Config Server Replica Set and mongos.请参阅部署配置服务器副本集和mongos
  3. Add the initial replica set as a shard. 将初始副本集添加为分片。See Add Initial Replica Set as a Shard.请参阅将初始副本集添加为分片
  4. Create a second shard and add to the cluster. 创建第二个分片并添加到集群。See Add Second Shard.请参见添加第二个分片
  5. Shard the desired collection. 切碎所需的集合。See Shard a Collection.请参阅分片集合

Considerations注意事项

Individual steps in these procedures note when downtime will occur.这些程序中的各个步骤会记录何时会发生停机。

Important重要

These procedures cause some downtime for your deployment.这些过程会导致部署停机。

Prerequisites先决条件

This tutorial uses a total of ten servers: one server for the mongos and three servers each for the first replica set, the second replica set, and the config server replica set.本教程总共使用十台服务器:一台服务器用于mongos,三台服务器分别用于第一个副本集、第二个副本集和配置服务器副本集

Each server must have a resolvable domain, hostname, or IP address within your system.每个服务器必须在系统中具有可解析的域、主机名或IP地址。

The tutorial uses the default data directories (e.g. /data/db and /data/configdb). 本教程使用默认的数据目录(例如/data/db/data/configdb)。Create the appropriate directories with appropriate permissions. 创建具有适当权限的适当目录。To use different paths, see Configuration File Options .要使用不同的路径,请参阅配置文件选项

Procedures过程

Set Up Initial Replica Set设置初始副本集

This procedure creates the initial three-member replica set rs0. 此过程创建初始的三成员副本集rs0The replica set members are on the following hosts: mongodb0.example.net, mongodb1.example.net, and mongodb2.example.net.副本集成员位于以下主机上:mongodb0.example.netmongodb1.example.netmongodb2.example.net

1

Start each member of the replica set with the appropriate options.使用适当的选项启动复制副本集的每个成员。

For each member, start a mongod instance with the following settings:对于每个成员,使用以下设置启动mongod实例:

  • Set replication.replSetName option to the replica set name. replication.replSetName选项设置为副本集名称。If your application connects to more than one replica set, each set must have a distinct name.如果应用程序连接到多个副本集,则每个副本集必须具有不同的名称。
  • Set net.bindIp option to the hostname/ip or a comma-delimited list of hostnames/ips.net.bindIp选项设置为主机名/ip或以逗号分隔的主机名/ips列表。
  • Set any other settings as appropriate for your deployment.根据您的部署设置适当的任何其他设置。

In this tutorial, the three mongod instances are associated with the following hosts:在本教程中,三个mongod实例与以下主机关联:

Replica Set Member副本集成员Hostname主机名
Member 0mongodb0.example.net
Member 1mongodb1.example.net
Member 2mongodb2.example.net

The following example specifies the replica set name and the ip binding through the --replSet and --bind_ip command-line options:以下示例通过--replSet--bind_ip命令行选项指定副本集名称和ip绑定:

Warning警告

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证加强网络基础设施

mongod --replSet "rs0" --bind_ip localhost,<hostname(s)|ip address(es)>

For <hostname(s)|ip address(es)>, specify the hostname(s) and/or ip address(es) for your mongod instance that remote clients (including the other members of the replica set) can use to connect to the instance.对于<hostname(s)|ip address(es)>,指定远程客户端(包括副本集的其他成员)可以用来连接到该实例的mongod实例的主机名和/或ip地址。

Alternatively, you can also specify the replica set name and the ip addresses in a configuration file:或者,您也可以在配置文件中指定replica set nameip addresses

replication:
   replSetName: "rs0"
net:
   bindIp: localhost,<hostname(s)|ip address(es)>

To start mongod with a configuration file, specify the configuration file's path with the --config option:要使用配置文件启动mongod,请使用--config选项指定配置文件的路径:

mongod --config <path-to-config>

In production deployments, you can configure a init script to manage this process. 在生产部署中,可以配置init脚本来管理此过程。Init scripts are beyond the scope of this document.初始化脚本超出了本文档的范围。

2

Connect mongosh to one of the mongod instances.mongosh连接到其中一个mongod实例。

From the same machine where one of the mongod is running (in this tutorial, mongodb0.example.net), start mongosh. 在运行mongod之一的同一台机器上(在本教程中为mongodb0.example.net),启动mongoshTo connect to the mongod listening to localhost on the default port of 27017, simply issue:要连接到默认端口27017上监听localhost的mongod,只需发出:

mongo

Depending on your path, you may need to specify the path to the mongosh binary.根据您的路径,您可能需要指定mongosh二进制文件的路径。

3

Initiate the replica set.启动副本集。

From mongosh, run rs.initiate() on replica set member 0.mongosh,对副本集成员0运行rs.initiate()

Important重要

Run rs.initiate() on just one and only onemongod instance for the replica set.仅在副本集的一个且仅一个mongod实例上运行rs.initiate()

Important重要

To avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. 为了避免由于IP地址更改而进行配置更新,请使用DNS主机名而不是IP地址。It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members.配置副本集成员或分片群集成员时,使用DNS主机名而不是IP地址尤为重要。

Use hostnames instead of IP addresses to configure clusters across a split network horizon. 使用主机名而不是IP地址跨拆分的网络范围配置群集。Starting in MongDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.从MongDB 5.0开始,仅配置了IP地址的节点将无法通过启动验证,无法启动。

rs.initiate( {
   _id : "rs0",
   members: [
      { _id: 0, host: "mongodb0.example.net:27017" },
      { _id: 1, host: "mongodb1.example.net:27017" },
      { _id: 2, host: "mongodb2.example.net:27017" }
   ]
})

MongoDB initiates a replica set, using the default replica set configuration.MongoDB使用默认副本集配置启动副本集。

4

Create and populate a new collection.创建并填充新集合。

The following step adds one million documents to the collection test_collection and can take several minutes depending on your system.以下步骤将向集合test_collection添加100万个文档,可能需要几分钟的时间,具体取决于您的系统。

To determine the primary, use rs.status().要确定主节点,请使用rs.status()

Issue the following operations on the primary of the replica set:在副本集的主副本上执行以下操作:

use test
var bulk = db.test_collection.initializeUnorderedBulkOp();
people = ["Marc", "Bill", "George", "Eliot", "Matt", "Trey", "Tracy", "Greg", "Steve", "Kristina", "Katie", "Jeff"];
for(var i=0; i<1000000; i++){
   user_id = i;
   name = people[Math.floor(Math.random()*people.length)];
   number = Math.floor(Math.random()*10001);
   bulk.insert( { "user_id":user_id, "name":name, "number":number });
}
bulk.execute();

For more information on deploying a replica set, see Deploy a Replica Set.有关部署副本集的更多信息,请参阅部署副本集

Deploy Config Server Replica Set and mongos部署配置服务器副本集和mongos

This procedure deploys the three-member replica set for the config servers and the mongos.此过程为config服务器mongos部署三成员副本集。

  • The config servers use the following hosts: mongodb7.example.net, mongodb8.example.net, and mongodb9.example.net.配置服务器使用以下主机:mongodb7.example.netmongodb8.example.netmongodb9.example.net
  • The mongos uses mongodb6.example.net.mongos使用mongodb6.example.net
1

Deploy the config servers as a three-member replica set.将配置服务器部署为三成员副本集。

Start a config server on mongodb7.example.net, mongodb8.example.net, and mongodb9.example.net. mongodb7.example.netmongodb8.example.netmongodb9.example.net上启动配置服务器。Specify the same replica set name. 指定相同的副本集名称。The config servers use the default data directory /data/configdb and the default port 27019.配置服务器使用默认数据目录/data/configdb和默认端口27019

Warning警告

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证加强网络基础设施

mongod --configsvr --replSet configReplSet --bind_ip localhost,<hostname(s)|ip address(es)>

To modify the default settings or to include additional options specific to your deployment, see mongod or Configuration File Options.要修改默认设置或包含特定于展开的其他选项,请参阅mongod配置文件选项

Connect mongosh to one of the config servers and run rs.initiate() to initiate the replica set.mongosh连接到一个配置服务器,然后运行rs.initiate()以启动副本集。

Important重要

Run rs.initiate() on just one and only onemongod instance for the replica set.仅在副本集的一个且仅一个mongod实例上运行rs.initiate()

Important重要

To avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. 为了避免由于IP地址更改而进行配置更新,请使用DNS主机名而不是IP地址。It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members.配置副本集成员或分片群集成员时,使用DNS主机名而不是IP地址尤为重要。

Use hostnames instead of IP addresses to configure clusters across a split network horizon. 使用主机名而不是IP地址跨拆分的网络范围配置群集。Starting in MongDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.从MongDB 5.0开始,仅配置了IP地址的节点将无法通过启动验证,无法启动。

rs.initiate( {
   _id: "configReplSet",
   configsvr: true,
   members: [
      { _id: 0, host: "mongodb07.example.net:27019" },
      { _id: 1, host: "mongodb08.example.net:27019" },
      { _id: 2, host: "mongodb09.example.net:27019" }
   ]
} )
2

Start a mongos instance.启动mongos实例。

On mongodb6.example.net, start the mongos specifying the config server replica set name followed by a slash / and at least one of the config server hostnames and ports.mongodb6.example.net上,启动mongos,指定配置服务器副本集名称,后跟斜杠/和至少一个配置服务器主机名和端口。

mongos --configdb configReplSet/mongodb07.example.net:27019,mongodb08.example.net:27019,mongodb09.example.net:27019  --bind_ip localhost,<hostname(s)|ip address(es)>

Restart the Replica Set as a Shard将副本集重新启动为分片

For sharded clusters, mongod instances for the shards must explicitly specify its role as a shardsvr, either via the configuration file setting sharding.clusterRole or via the command line option --shardsvr.对于分片集群,分片的mongod实例必须通过配置文件设置sharding.clusterRole或通过命令行选项--shardsvr显式指定其角色作为shardsvr

Note注意

Default port for mongod instances with the shardsvr role is 27018. 具有shardsvr角色的mongod实例的默认端口为27018To use a different port, specify net.port setting or --port option.要使用其他端口,请指定net.port设置或--port选项。

1

Determine the primary and secondary members.确定主要成员和次要成员。

Connect mongosh to one of the members and run rs.status() to determine the primary and secondary members.mongosh连接到其中一个成员,然后运行rs.status()来确定主要成员和次要成员。

2

Restart secondary members with the --shardsvr option.使用--shardsvr选项重新启动次要成员。

One secondary at a time, shut down and restart each secondary with the --shardsvr option.一次一个辅助服务器,使用--shardsvr选项关闭并重新启动每个辅助服务器。

Warning警告

This step requires some downtime for applications connected to secondary members of the replica set. 此步骤要求连接到副本集辅助成员的应用程序停机。Applications connected to a secondary may error with CannotVerifyAndSignLogicalTime after restarting the secondary until you perform the steps in Add Initial Replica Set as a Shard. 连接到辅助服务器的应用程序在重新启动辅助服务器后可能会出现CannotVerifyAndSignLogicalTime错误,直到您执行将初始副本集添加为分片中的步骤为止。Restarting your application will also stop it from receiving CannotVerifyAndSignLogicalTime errors.重新启动应用程序也会阻止它接收CannotVerifyAndSignLogicalTime错误。

To continue to use the same port, include the --port option. 要继续使用同一端口,请包括--port选项。Include additional options, such as --bind_ip, as appropriate for your deployment.根据您的部署,包括其他选项,例如--bind_ip

Warning警告

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证加强网络基础设施

mongod --replSet "rs0" --shardsvr --port 27017 --bind_ip localhost,<hostname(s)|ip address(es)>

Include any other options as appropriate for your deployment. 包括适合您的部署的任何其他选项。Repeat this step for the other secondary.对其他辅助设备重复此步骤。

3

Step down the primary.降低主服务器。

Connect mongosh to the primary and stepdown the primary.mongosh连接到主服务器,然后逐步降低主服务器。

Warning警告

This step requires some downtime. 此步骤需要一些停机时间。Applications may error with CannotVerifyAndSignLogicalTime after stepping down the primary until you perform the steps in Add Initial Replica Set as a Shard. 在执行“将初始副本集添加为分片”中的步骤之前,应用程序在逐步停止主副本后可能会出现CannotVerifyAndSignLogicalTime错误。Restarting your application will also stop it from receiving CannotVerifyAndSignLogicalTime errors.重新启动应用程序也会阻止它接收CannotVerifyAndSignLogicalTime错误。

rs.stepDown()
4

Restart the primary with the --shardsvr option.使用--shardsvr选项重新启动主服务器。

Shut down the primary and restart with the --shardsvr option.关闭主服务器,然后使用--shardsvr选项重新启动。

To continue to use the same port, include the --port option.要继续使用同一端口,请包括--port选项。

mongod --replSet "rs0" --shardsvr --port 27017 --bind_ip localhost,<hostname(s)|ip address(es)>

Include any other options as appropriate for your deployment.包括适合您的部署的任何其他选项。

Add Initial Replica Set as a Shard将初始副本集添加为分片

The following procedure adds the initial replica set rs0 as a shard.以下过程将初始副本集rs0添加为分片。

1

Connect mongosh to the mongos.mongosh连接到mongos

mongosh mongodb6.example.net:27017/admin
2

Add the shard.添加分片。

Add a shard to the cluster with the sh.addShard() method:使用sh.addShard()方法将分片添加到群集中:

sh.addShard( "rs0/mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017" )

Add Second Shard添加第二个分片

The following procedure deploys a new replica set rs1 for the second shard and adds it to the cluster. 以下过程为第二个分片部署一个新的副本集rs1,并将其添加到集群中。The replica set members are on the following hosts: mongodb3.example.net, mongodb4.example.net, and mongodb5.example.net.副本集成员位于以下主机上:mongodb3.example.netmongodb4.example.netmongodb5.example.net

For sharded clusters, mongod instances for the shards must explicitly specify its role as a shardsvr, either via the configuration file setting sharding.clusterRole or via the command line option --shardsvr.对于分片集群,分片的mongod实例必须通过配置文件设置sharding.clusterRole或通过命令行选项--shardsvr显式指定其角色作为shardsvr

Note注意

Default port for mongod instances with the shardsvr role is 27018. 具有shardsvr角色的mongod实例的默认端口为27018To use a different port, specify net.port setting or --port option.要使用其他端口,请指定net.port设置或--port选项。

1

Start each member of the replica set with the appropriate options.使用适当的选项启动复制副本集的每个成员。

For each member, start a mongod, specifying the replica set name through the --replSet option and its role as a shard with the --shardsvr option. 对于每个成员,启动一个mongod,通过--replSet选项指定副本集名称,并使用--shardsvr选项指定其作为分片的角色。Specify additional options, such as --bind_ip, as appropriate.根据需要指定其他选项,例如--bind_ip

Warning警告

Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. 在绑定到非本地主机(例如,可公开访问的)IP地址之前,请确保已保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist. 有关安全建议的完整列表,请参阅安全检查表At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证加强网络基础设施

For replication-specific parameters, see Replication Options.有关复制特定的参数,请参阅复制选项

mongod --replSet "rs1" --shardsvr --port 27017 --bind_ip localhost,<hostname(s)|ip address(es)>

Repeat this step for the other two members of the rs1 replica set.rs1副本集的其他两个成员重复此步骤。

2

Connect mongosh to a replica set member.mongosh连接到副本集成员。

Connect mongosh to one member of the replica set (e.g. mongodb3.example.net)mongosh连接到副本集的一个成员(例如mongodb3.example.net

mongosh mongodb3.example.net
3

Initiate the replica set.启动副本集。

From mongosh, run rs.initiate() to initiate a replica set that consists of the current member.mongosh中,运行rs.initiate()以启动由当前成员组成的副本集。

Important重要

Run rs.initiate() on just one and only onemongod instance for the replica set.仅在副本集的一个且仅一个mongod实例上运行rs.initiate()

Important重要

To avoid configuration updates due to IP address changes, use DNS hostnames instead of IP addresses. 为了避免由于IP地址更改而进行配置更新,请使用DNS主机名而不是IP地址。It is particularly important to use a DNS hostname instead of an IP address when configuring replica set members or sharded cluster members.配置副本集成员或分片群集成员时,使用DNS主机名而不是IP地址尤为重要。

Use hostnames instead of IP addresses to configure clusters across a split network horizon. 使用主机名而不是IP地址跨拆分的网络范围配置群集。Starting in MongDB 5.0, nodes that are only configured with an IP address will fail startup validation and will not start.从MongDB 5.0开始,仅配置了IP地址的节点将无法通过启动验证,无法启动。

rs.initiate( {
   _id : "rs1",
   members: [
       { _id: 0, host: "mongodb3.example.net:27017" },
       { _id: 1, host: "mongodb4.example.net:27017" },
       { _id: 2, host: "mongodb5.example.net:27017" }
   ]
})
4

Connect mongosh to the mongos.mongosh连接到mongos

mongosh mongodb6.example.net:27017/admin
5

Add the shard.添加分片。

In mongosh, when connected to the mongos, add the shard to the cluster with the sh.addShard() method:mongosh中,当连接到mongos时,使用sh.addShard()方法将分片添加到集群中:

sh.addShard( "rs1/mongodb3.example.net:27017,mongodb4.example.net:27017,mongodb5.example.net:27017" )

Shard a Collection分享集合

1

Connect mongosh to the mongos.mongosh连接到mongos

mongosh mongodb6.example.net:27017/admin
2

Enable sharding for a database.为数据库启用分片。

Before you can shard a collection, you must first enable sharding for the collection's database. 在对集合进行分片之前,必须首先对集合的数据库启用分片。Enabling sharding for a database does not redistribute data but makes it possible to shard the collections in that database.为数据库启用分片不会重新分发数据,但可以对该数据库中的集合进行分片。

The following operation enables sharding on the test database:以下操作在test数据库上启用分片:

sh.enableSharding( "test" )

mongos uses "majority" for the enableSharding command and its helper sh.enableSharding().mongosenableSharding命令及其助手shenableSharding()使用"majority"

The operation returns the status of the operation:操作返回操作的状态:

{ "ok" : 1 }
3

Determine the shard key.确定分片键。

For the collection to shard, determine the shard key. 对于要分片的集合,确定分片键。The shard key determines how MongoDB distributes the documents between shards. 分片键决定MongoDB如何在shard之间分发文档。Good shard keys:好的分片键:

  • have values that are evenly distributed among all documents,具有在所有文档中均匀分布的值,
  • group documents that are often accessed at the same time into contiguous chunks, and将经常同时访问的文档分组为连续的块,以及
  • allow for effective distribution of activity among shards.允许在分片之间有效地分配活动。

For more information, see Choose a Shard Key.有关详细信息,请参阅选择分片键

This procedure will use the number field as the shard key for test_collection.此过程将使用number字段作为test_collection的分片键。

4

Create an index on the shard key.在分片键上创建索引。

Before sharding a non-empty collection, create an index on the shard key.在分片非空集合之前,请在分片键上创建索引

use test
db.test_collection.createIndex( { number : 1 } )
5

Shard the collection.将集合切成分片。

In the test database, shard the test_collection, specifying number as the shard key.test数据库中,分片test_collection,指定数字作为分片键。

use test
sh.shardCollection( "test.test_collection", { "number" : 1 } )

mongos uses "majority" for the write concern of the shardCollection command and its helper sh.shardCollection().mongosshardCollection命令及其助手sh.shardCollection()写入关注使用"majority"

The method returns the status of the operation:该方法返回操作的状态:

{ "collectionsharded" : "test.test_collection", "ok" : 1 }

The balancer redistributes chunks of documents when it next runs. 平衡器在下次运行时重新分配大块文档。As clients insert additional documents into this collection, the mongos routes the documents to the appropriate shard.当客户端向这个集合中插入额外的文档时,mongos会将文档路由到适当的分片。

6

Confirm the shard is balancing.确认分片处于平衡状态。

To confirm balancing activity, run db.stats() or db.printShardingStatus() in the test database.要确认平衡活动,请在test数据库中运行db.stats()db.printShardingStatus()

use test
db.stats()
db.printShardingStatus()

Example output of the db.stats():db.stats()的输出示例:

{
  "raw" : {
      "rs0/mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017" : {
         "db" : "test",
         "collections" : 1,
         "views" : 0,
         "objects" : 640545,
         "avgObjSize" : 70.83200339949052,
         "dataSize" : 45370913,
         "storageSize" : 50438144,
         "numExtents" : 0,
         "indexes" : 2,
         "indexSize" : 24502272,
         "ok" : 1,
         "$gleStats" : {
                     "lastOpTime" : Timestamp(0, 0),
                     "electionId" : ObjectId("7fffffff0000000000000003")
                  }
      },
      "rs1/mongodb3.example.net:27017,mongodb4.example.net:27017,mongodb5.example.net:27017" : {
         "db" : "test",
         "collections" : 1,
         "views" : 0,
         "objects" : 359455,
         "avgObjSize" : 70.83259935179647,
         "dataSize" : 25461132,
         "storageSize" : 8630272,
         "numExtents" : 0,
         "indexes" : 2,
         "indexSize" : 8151040,
         "ok" : 1,
         "$gleStats" : {
            "lastOpTime" : Timestamp(0, 0),
            "electionId" : ObjectId("7fffffff0000000000000001")
         }
      }
  },
  "objects" : 1000000,
  "avgObjSize" : 70,
  "dataSize" : 70832045,
  "storageSize" : 59068416,
  "numExtents" : 0,
  "indexes" : 4,
  "indexSize" : 32653312,
  "fileSize" : 0,
  "extentFreeList" : {
      "num" : 0,
      "totalSize" : 0
  },
  "ok" : 1
}

Example output of the db.printShardingStatus():db.printShardingStatus()的输出示例:

--- Sharding Status ---
sharding version: {
   "_id" : 1,
   "minCompatibleVersion" : 5,
   "currentVersion" : 6,
   "clusterId" : ObjectId("5be0a488039b1964a7208c60")
}
shards:
   {  "_id" : "rs0",  "host" : "rs0/mongodb0.example.net:27017,mongodb1.example.net:27017,mongodb2.example.net:27017",  "state" : 1 }
   {  "_id" : "rs1",  "host" : "rs1/mongodb3.example.net:27017,mongodb4.example.net:27017,mongodb5.example.net:27017",  "state" : 1 }
active mongoses:
   "3.6.8" : 1
autosplit:
   Currently enabled: yes
balancer:
   Currently enabled:  yes
   Currently running:  yes
   Collections with active migrations:
      test.test_collection started at Mon Nov 05 2018 15:16:45 GMT-0500
Failed balancer rounds in last 5 attempts:  0
Migration Results for the last 24 hours: 
   1 : Success
databases:
   {  "_id" : "test", "primary" : "rs0", "partitioned" : true }
      test.test_collection
            shard key: { "number" : 1 }
            unique: false
            balancing: true
            chunks:
               rs0   5
               rs1   1
            { "number" : { "$minKey" : 1 } } -->> { "number" : 1195 } on : rs1 Timestamp(2, 0) 
            { "number" : 1195 } -->> { "number" : 2394 } on : rs0 Timestamp(2, 1) 
            { "number" : 2394 } -->> { "number" : 3596 } on : rs0 Timestamp(1, 5) 
            { "number" : 3596 } -->> { "number" : 4797 } on : rs0 Timestamp(1, 6) 
            { "number" : 4797 } -->> { "number" : 9588 } on : rs0 Timestamp(1, 1) 
            { "number" : 9588 } -->> { "number" : { "$maxKey" : 1 } } on : rs0 Timestamp(1, 2)

Run these commands for a second time to demonstrate that chunks are migrating from rs0 to rs1.再次运行这些命令,以演示正在从rs0迁移到rs1

←  Convert Sharded Cluster to Replica SetConvert a Shard Standalone to a Shard Replica Set →