翻译或纠错本页面

配置服务器

重要

配置服务器是保存集群中 元信息 的特殊 mongod . 配置服务器使用两段提交的方法来保证即时一致性和可靠性.配置服务器 并不 以复制集的方式运行,所有的配置服务器都可用是部署一个集群或者修改集群元信息的前提.

To convert your config servers from SCCC to CSRS, see Upgrade Config Servers to Replica Set.

生产环境中的集群有 精确的三个 配置服务器,在测试环境中,你可以只使用一个配置服务器来部署一个集群,但在生产环境中,为确保冗余与安全,应该总是使用三个.

The mongos instances cache this data and use it to route read and write operations to the correct shards. mongos updates the cache when there are metadata changes for the cluster, such as Chunk Splits or adding a shard. Shards also read chunk metadata from the config servers.

如果你的集群只有一个配置服务器,那这个配置服务是单点服务,如果这个配置服务器不能被访问,集群将不可服务,如果你不能将配置服务器的数据恢复,整个集群将不能再被使用.

MongoDB also uses the config servers to manage distributed locks.

Each sharded cluster must have its own config servers. Do not use the same config servers for different sharded clusters.

警告

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

在 3.4 版更改.

Starting in MongoDB 3.2, config servers for sharded clusters can be deployed as a replica set (CSRS) instead of three mirrored config servers (SCCC). 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. 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. To deploy config servers as a replica set, the config servers must run the WiredTiger storage engine.

使用CNAMEs标记你的配置服务器,这样可以在重命名或者改变配置服务器的顺序时不需要停机.

The following restrictions apply to a replica set configuration when used for config servers:

  • 配置服务器在 config 数据库 中存储了集群的元信息, mongos 缓存了这个数据库用来做读写的路由分发.

  • Must have no delayed members.
  • Must build indexes (i.e. no member should have buildIndexes setting set to false).

对存在的数据块进行分裂,详细信息可以参见 数据块分裂.

在分片间进行数据块的迁移,详细信息可以参见 数据块的迁移.

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.

The config database contains the collections that contain the sharded cluster metadata. MongoDB writes data to the config database when the metadata changes, such as after a chunk migration or a chunk split.

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".

Reads from Config Servers

如果集群中一个或者两个配置服务器不可用,集群的元信息将变为 可读 ,你还可以从分片中读写信息,但是数据块的迁移以及数据块的分裂在所有配置服务器都恢复可用之前不能够进行.

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.

如果所有的三个配置服务器都不可用,在重启 mongos 之前集群依然可用. 但是一旦试图重启 mongos ,集群将不能提供任何服务.

Config Server Availability

没有集群的元信息,集群将不能正常工作,因此,要 时刻 保持配置服务器的可用和完整.因此,配置服务器的备份是很重要的.与分片中的数据相比,配置服务器存储的信息要小很多.这意味着配置服务器有相对较小的请求负载,而且对于集群的正常运行,并不需要所有配置服务器任意时刻都可用,所以,备份配置服务器是一件容易的事情.

如果集群使用的配置服务器变换了ip或者域名,你需要重启 所有mongodmongos .可以在集群部署时使用CNAMEs避免重启.

Clusters become inoperable without the cluster metadata. 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.

重要

Always back up the config database before doing any maintenance on the config server.

To access the config database, issue the following command from the mongo shell:

use config

In general, you should never edit the content of the config database directly. The config database contains the following collections:

For more information on these collections and their role in sharded clusters, see Config Database. See 对存在的数据块进行分裂,详细信息可以参见 数据块分裂. for more information about reads and updates to the metadata.

Sharded Cluster Security

Use Internal 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.

See Deploy Sharded Cluster with Keyfile Access Control for a tutorial on deploying a secured sharded cluster.

←   分片 mongos  →