Docs HomeMongoDB Manual

Config Servers配置服务器

Important

Starting in 3.4, the use of the deprecated mirrored mongod instances as config servers (SCCC) is no longer supported. 从3.4开始,不再支持使用不推荐使用的镜像mongod实例作为配置服务器(SCCC)。Before you can upgrade your sharded clusters to 3.4, you must convert your config servers from SCCC to CSRS.在将分片集群升级到3.4之前,必须将配置服务器从SCCC转换为CSRS。

To convert your config servers from SCCC to CSRS, see the MongoDB 3.4 manual Upgrade Config Servers to Replica Set.要将配置服务器从SCCC转换为CSRS,请参阅MongoDB 3.4手册将配置服务器升级到副本集

Config servers store the metadata for a sharded cluster. 配置服务器存储分片集群的元数据。The metadata reflects state and organization for all data and components within the sharded cluster. 元数据反映了分片集群中所有数据和组件的状态和组织。The metadata includes the list of chunks on every shard and the ranges that define the chunks.元数据包括每个分片上的块列表以及定义块的范围。

The mongos instances cache this data and use it to route read and write operations to the correct shards. mongos实例缓存这些数据,并使用它将读写操作路由到正确的分片。mongos updates the cache when there are metadata changes for the cluster, such as adding a shard. 当集群的元数据发生更改时,mongos会更新缓存,例如添加分片Shards also read chunk metadata from the config servers.分片还从配置服务器读取块元数据。

The config servers also store Authentication configuration information such as Role-Based Access Control or internal authentication settings for the cluster.配置服务器还存储身份验证配置信息,例如基于角色的访问控制或集群的内部身份验证设置。

MongoDB also uses the config servers to manage distributed locks.MongoDB还使用配置服务器来管理分布式锁。

Each sharded cluster must have its own config servers. 每个分片集群都必须有自己的配置服务器。Do not use the same config servers for different sharded clusters.不要将相同的配置服务器用于不同的分片集群。

Warning

Administrative operations conducted on config servers may have significant impact on sharded cluster performance and availability. 在配置服务器上执行的管理操作可能会对分片集群的性能和可用性产生重大影响。Depending on the number of config servers impacted, the cluster may be read-only or offline for a period of time.根据受影响的配置服务器的数量,集群可能在一段时间内处于只读或脱机状态。

Replica Set Config Servers副本集配置服务器

Changed in version 3.4.在版本3.4中进行了更改。

Config servers for sharded clusters can be deployed as a replica set (CSRS). 分片集群的配置服务器可以作为副本集(CSRS)进行部署。Using a replica set for the config servers improves consistency across the config servers, since MongoDB can take advantage of the standard replica set read and write protocols for the config data. 为配置服务器使用副本集可以提高配置服务器之间的一致性,因为MongoDB可以利用配置数据的标准副本集读写协议。In addition, using a replica set for config servers allows a sharded cluster to have more than 3 config servers since a replica set can have up to 50 members. 此外,为配置服务器使用副本集允许分片集群拥有3个以上的配置服务器,因为副本集最多可以有50个成员。To deploy config servers as a replica set, the config servers must run the WiredTiger Storage Engine.要将配置服务器部署为副本集,配置服务器必须运行WiredTiger存储引擎

The following restrictions apply to a replica set configuration when used for config servers:以下限制适用于用于配置服务器的副本集配置:

Read and Write Operations on Config Servers配置服务器上的读写操作

The admin database and the config database exist on the config servers.配置服务器上存在管理数据库和配置数据库

Writes to Config Servers写入配置服务器

The admin database contains the collections related to the authentication and authorization as well as the other system.* collections for internal use.admin数据库包含与身份验证和授权相关的集合,以及供内部使用的其他system.*集合

The config database contains the collections that contain the sharded cluster metadata. config数据库包含包含分片集群元数据的集合。MongoDB writes data to the config database when the metadata changes, such as after a chunk migration or a chunk split.当元数据发生变化时,例如在块迁移块拆分之后,MongoDB会将数据写入config数据库

Users should avoid writing directly to the config database in the course of normal operation or maintenance.用户应避免在正常操作或维护过程中直接写入配置数据库。

When writing to the config servers, MongoDB uses a write concern of "majority".在向配置服务器写入时,MongoDB使用"majority"写入关注

Reads from Config Servers从配置服务器读取

MongoDB reads from the admin database for authentication and authorization data and other internal uses.MongoDB从admin数据库中读取身份验证和授权数据以及其他内部用途。

MongoDB reads from the config database when a mongos starts or after a change in the metadata, such as after a chunk migration. Shards also read chunk metadata from the config servers.MongoDB在mongos启动时或元数据更改后(如块迁移后)从config数据库中读取。分片还从config服务器读取块元数据。

When reading from the replica set config servers, MongoDB uses a Read Concern level of "majority".当从副本集配置服务器读取时,MongoDB使用"majority"读取关注级别。

Config Server Availability配置服务器可用性

If the config server replica set loses its primary and cannot elect a primary, the cluster's metadata becomes read only. 如果配置服务器副本集丢失其主副本,并且无法选择主副本,则集群的元数据将变为只读You can still read and write data from the shards, but no chunk migration or chunk splits will occur until the replica set can elect a primary.您仍然可以从分片中读取和写入数据,但在副本集可以选择主副本之前,不会发生区块迁移或区块拆分。

In a sharded cluster, mongod and mongos instances monitor the replica sets in the sharded cluster (e.g. shard replica sets, config server replica set).在分片集群中,mongodmongos实例监视分片集群的副本集(例如,分片副本集、配置服务器副本集)。

If all config servers become unavailable, the cluster can become inoperable. 如果所有配置服务器都不可用,则集群可能无法运行。To ensure that the config servers remain available and intact, backups of config servers are critical. 为了确保配置服务器保持可用和完整,配置服务器的备份至关重要。The data on the config server is small compared to the data stored in a cluster, and the config server has a relatively low activity load.与存储在集群中的数据相比,配置服务器上的数据较小,并且配置服务器的活动负载相对较低。

See A Config Server Replica Set Member Become Unavailable for more information.有关详细信息,请参阅配置服务器副本集成员变得不可用

Sharded Cluster Metadata分片化群集元数据

Config servers store metadata in the Config Database.配置服务器将元数据存储在配置数据库中。

Important

Always back up the config database before doing any maintenance on the config server.在对配置服务器进行任何维护之前,请始终备份config数据库。

To access the config database, issue the following command in mongosh:要访问config数据库,请在mongosh中发出以下命令:

use config

In general, you should never edit the content of the config database directly. 通常,您不应该直接编辑config数据库的内容。The config database contains the following collections:config数据库包含以下集合:

For more information on these collections and their role in sharded clusters, see Config Database. 有关这些集合及其在分片集群中的作用的更多信息,请参阅配置数据库See Read and Write Operations on Config Servers for more information about reads and updates to the metadata.有关元数据读取和更新的详细信息,请参阅配置服务器上的读取和写入操作

Sharded Cluster Security分片集群安全

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.有关部署安全分片集群的教程,请参阅使用键文件身份验证部署分片集群