On this page本页内容
A shard contains a subset of sharded data for a sharded cluster. 分片包含分片集群的分片数据子集。Together, the cluster's shards hold the entire data set for the cluster.集群的分片一起保存集群的整个数据集。
As of MongoDB 3.6, shards must be deployed as a replica set to provide redundancy and high availability.从MongoDB 3.6开始,分片必须作为副本集部署,以提供冗余和高可用性。
Users, clients, or applications should only directly connect to a shard to perform local administrative and maintenance operations.用户、客户端或应用程序只应直接连接到分片以执行本地管理和维护操作。
Performing queries on a single shard only returns a subset of data. 对单个分片执行查询只返回数据的子集。Connect to the 连接到mongos
to perform cluster level operations, including read or write operations.mongos
以执行群集级别的操作,包括读或写操作。
Each database in a sharded cluster has a primary shard that holds all the un-sharded collections for that database. 分片集群中的每个数据库都有一个主分片,用于保存该数据库的所有未分片集合。Each database has its own primary shard. 每个数据库都有自己的主分片。The primary shard has no relation to the primary in a replica set.主分片与副本集中的primary没有关系。
The mongos
selects the primary shard when creating a new database by picking the shard in the cluster that has the least amount of data. mongos
在创建新数据库时,通过在集群中选取数据量最少的分片来选择主分片。mongos
uses the totalSize
field returned by the listDatabases
command as a part of the selection criteria.mongos
使用listDatabases
命令返回的totalSize
字段作为选择条件的一部分。
To change the primary shard for a database, use the 要更改数据库的主分片,请使用movePrimary
command. movePrimary
命令。The process of migrating the primary shard may take significant time to complete, and you should not access the collections associated to the database until it completes. 迁移主分片的过程可能需要很长时间才能完成,在迁移完成之前,不应访问与数据库关联的集合。Depending on the amount of data being migrated, the migration may affect overall cluster operations. 根据要迁移的数据量,迁移可能会影响整个群集操作。Consider the impact to cluster operations and network load before attempting to change the primary shard.在尝试更改主分片之前,请考虑对群集操作和网络负载的影响。
When you deploy a new sharded cluster with shards that were previously used as replica sets, all existing databases continue to reside on their original replica sets. 当您使用以前用作副本集的分片部署新的分片集群时,所有现有数据库都将继续驻留在其原始副本集上。Databases created subsequently may reside on any shard in the cluster.随后创建的数据库可以驻留在集群中的任何分片上。
Use the 使用sh.status()
method in mongosh
to see an overview of the cluster. mongosh
中的sh.status()
方法查看集群的概述。This reports includes which shard is primary for the database and the chunk distribution across the shards. 该报告包括哪个分片是数据库的主要分片,以及分片之间的区块分布。See 有关详细信息,请参阅sh.status()
method for more details.sh.status()
方法。
Use Internal/Membership Authentication to enforce intra-cluster security and prevent unauthorized cluster components from accessing the cluster. 使用内部/成员身份验证来实施集群内安全,并防止未经授权的集群组件访问集群。You must start each 必须使用适当的安全设置启动群集中的每个mongod
in the cluster with the appropriate security settings in order to enforce internal authentication.mongod
,以强制执行内部身份验证。
Starting in MongoDB 5.3, SCRAM-SHA-1 cannot be used for intra-cluster authentication. 从MongoDB 5.3开始,SCRAM-SHA-1不能用于集群内身份验证。Only SCRAM-SHA-256 is supported.仅支持SCRAM-SHA-256。
In previous MongoDB versions, SCRAM-SHA-1 and SCRAM-SHA-256 can both be used for intra-cluster authentication, even if SCRAM is not explicitly enabled.在以前的MongoDB版本中,SCRAM-SHA-1和SCRAM-SHA-256都可以用于集群内身份验证,即使没有明确启用SCRAM。
See Deploy Sharded Cluster with Keyfile Authentication for a tutorial on deploying a secured sharded cluster.有关部署安全分片集群的教程,请参阅使用密钥文件身份验证部署分片集群。
Each shard supports Role-Based Access Control (RBAC) for restricting unauthorized access to shard data and operations. 每个分片都支持基于角色的访问控制(RBAC),以限制对分片数据和操作的未经授权访问。Start each 使用mongod
in the replica set with the --auth
option to enforce RBAC. --auth
选项启动副本集中的每个mongod
以强制RBAC。Alternatively, enforcing Internal/Membership Authentication for intra-cluster security also enables user access controls via RBAC.或者,为集群内安全实施内部/成员身份验证也可以通过RBAC实现用户访问控制。
Starting in MongoDB 5.3, SCRAM-SHA-1 cannot be used for intra-cluster authentication. 从MongoDB 5.3开始,SCRAM-SHA-1不能用于集群内身份验证。Only SCRAM-SHA-256 is supported.仅支持SCRAM-SHA-256。
In previous MongoDB versions, SCRAM-SHA-1 and SCRAM-SHA-256 can both be used for intra-cluster authentication, even if SCRAM is not explicitly enabled.在以前的MongoDB版本中,SCRAM-SHA-1和SCRAM-SHA-256都可以用于集群内身份验证,即使没有明确启用SCRAM。
Each shard has its own shard-local users. These users cannot be used on other shards, nor can they be used for connecting to the cluster via a 每个分片都有自己的分片本地用户。这些用户不能在其他分片上使用,也不能通过mongos
.mongos
连接到集群。
See Enable Access Control for a tutorial on enabling adding users to an RBAC-enabled MongoDB deployment.有关如何将用户添加到启用RBAC的MongoDB部署的教程,请参阅启用访问控制。