Starting in MongoDB 8.0, you can configure a config server to store your application data in addition to the usual sharded cluster metadata. A 从MongoDB 8.0开始,您可以配置配置服务器来存储应用程序数据以及通常的分片集群元数据。同时提供配置服务器和分片服务器功能的mongod node that provides both config server and shard server functionality is called a config shard. mongod节点称为配置分片。A 没有分片服务器功能的mongod node that runs as a standalone --configsvr without shard server functionality is called a dedicated config server.mongod节点作为独立的--configsvr运行,称为专用配置服务器。
A sharded cluster must have a config server, but it can be either a config shard (embedded config server) or a dedicated config server. Using a config shard reduces the number of nodes required and can simplify your deployment. 分片集群必须有一个配置服务器,但它可以是配置分片(嵌入式配置服务器)或专用配置服务器。使用配置分片可以减少所需的节点数量,并简化部署。A config shard cluster is also called an embedded config server cluster. You cannot use the same config server for multiple sharded clusters.配置分片集群也称为嵌入式配置服务器集群。您不能将同一配置服务器用于多个分片集群。
Use Cases用例
You can consider using a config shard if your cluster has three or fewer shards.如果集群有三个或更少的分片,你可以考虑使用配置分片。
If your application has demanding availability and resiliency requirements, consider deploying a dedicated config server. A dedicated config server provides isolation, dedicated resources, and consistent performance for critical cluster operations.如果应用程序具有苛刻的可用性和弹性要求,请考虑部署专用配置服务器。专用配置服务器为关键集群操作提供隔离、专用资源和一致的性能。
You should use a dedicated config server if you satisfy one or more of the following conditions:如果满足以下一个或多个条件,则应使用专用配置服务器:
You plan to use more than three shards.您计划使用三个以上的分片。You plan to use Queryable Encryption collections.您计划使用可查询加密集合。You plan to use queryable backups (on-prem).您计划使用可查询备份(本地)。
Behavior行为
In an embedded config server cluster, a config shard will be used to store cluster metadata and user data. It helps reduce the complexity of a sharded cluster deployment.在嵌入式配置服务器集群中,配置分片将用于存储集群元数据和用户数据。它有助于降低分片集群部署的复杂性。
You can store sharded and unsharded collection data in your config shard. It has all the properties of a shard as well as acting as the config server.您可以在配置分片中存储分片和非分片的集合数据。它具有分片的所有属性,并充当配置服务器。
Confirm use of Config Shard确认配置分片的使用
You can confirm that a sharded cluster uses a config shard by using one of the following methods:您可以使用以下方法之一确认分片集群使用配置分片:
Run the在sh.isConfigShardEnabled()method inmongosh.mongosh中运行sh.isConfigShardEnabled()方法。If the如果sh.isConfigShardEnabled()output containsenabled: true, the cluster uses a config shard. If the output containsenabled: false, the cluster does not use a config shard.sh.isConfigShardEnabled()输出包含enabled: true,则集群使用配置分片。如果输出包含enabled:false,则集群不使用配置分片。Run the在连接到listShardscommand against theadmindatabase while connected to amongosand inspect the output for a document where_idis set to"config".mongos时,对admin数据库运行listShards命令,并检查_id设置为"config"的文档的输出。If the如果listShardsoutput does not contain a document where_idis set to"config", the cluster does not use a config shard.listShards输出不包含_id设置为"config"的文档,则集群不使用配置分片。
The following example runs the 以下示例运行listShards command and tries to find a document where _id is set to "config".listShards命令,并尝试查找_id设置为"config"的文档。
db.adminCommand({ listShards: 1 })["shards"].find(element => element._id === "config")
In this example, the returned document has 在这个例子中,返回的文档将_id set to "config" which confirms that this cluster uses a config shard._id设置为"config",这确认了该集群使用了配置分片。
{
_id: "config",
host: "configRepl/localhost:27018",
state: 1,
topologyTime: Timestamp({ t: 1732218671, i: 13 }),
replSetConfigVersion: Long('-1')
}Commands命令
To configure a dedicated config server to run as a config shard, run the 要将专用配置服务器配置为作为配置分片运行,请运行transitionFromDedicatedConfigServer command.transitionFromDedicatedConfigServer命令。
To configure a config shard to run as a dedicated config server, run the 要将配置分片配置为作为专用配置服务器运行,请运行transitionToDedicatedConfigServer command.transitionToDedicatedConfigServer命令。