Sharded Cluster Components分片集群组件

On this page本页内容

A MongoDB sharded cluster consists of the following components:MongoDB分片集群由以下组件组成:

Production Configuration生产配置

In a production cluster, ensure that data is redundant and that your systems are highly available. 在生产集群中,确保数据是冗余的,并且系统是高可用的。Consider the following for a production sharded cluster deployment:对于生产分片集群部署,请考虑以下事项:

  • Deploy Config Servers as a 3 member replica set将配置服务器部署为3成员副本集
  • Deploy each Shard as a 3 member replica set将每个分片部署为一个3在成员副本集
  • Deploy one or more mongos routers部署一个或多个mongos路由器

Replica Set Distribution副本集分发

Where possible, consider deploying one member of each replica set in a site suitable for being a disaster recovery location.如果可能,请考虑在适合作为灾难恢复位置的站点中部署每个副本集的一个成员。

Note注意

Distributing replica set members across two data centers provides benefit over a single data center. 跨两个数据中心分发副本集成员比单个数据中心更具优势。In a two data center distribution,在两个数据中心的分布中,

  • If one of the data centers goes down, the data is still available for reads unlike a single data center distribution.如果其中一个数据中心出现故障,数据仍然可以读取,这与单个数据中心分发不同。
  • If the data center with a minority of the members goes down, the replica set can still serve write operations as well as read operations.如果拥有少数成员的数据中心宕机,副本集仍然可以执行写操作和读操作。
  • However, if the data center with the majority of the members goes down, the replica set becomes read-only.但是,如果包含大多数成员的数据中心关闭,副本集将变为只读。

If possible, distribute members across at least three data centers. For config server replica sets (CSRS), the best practice is to distribute across three (or more depending on the number of members) centers. 如果可能,将成员分布在至少三个数据中心。对于配置服务器副本集(CSR),最佳做法是跨三个(或更多,取决于成员数量)中心分发。If the cost of the third data center is prohibitive, one distribution possibility is to evenly distribute the data bearing members across the two data centers and store the remaining member in the cloud if your company policy allows.如果第三个数据中心的成本过高,一种分发可能性是在两个数据中心之间均匀地分发数据承载成员,并在公司政策允许的情况下将剩余成员存储在云中。

Number of Shards分片数

Sharding requires at least two shards to distribute sharded data. 分片需要至少两个分片来分发分片数据。Single shard sharded clusters may be useful if you plan on enabling sharding in the near future, but do not need to at the time of deployment.如果您计划在不久的将来启用分片,但在部署时不需要启用,那么单分片分片集群可能会很有用。

Number of mongos and Distributionmongos的数量和分布

Deploying multiple mongos routers supports high availability and scalability. 部署多个mongos路由器支持高可用性和可扩展性。A common pattern is to place a mongos on each application server. 一种常见的模式是在每个应用服务器上放置一个mongosDeploying one mongos router on each application server reduces network latency between the application and the router.在每个应用服务器上部署一个mongos路由器可以减少应用程序和路由器之间的网络延迟。

Alternatively, you can place a mongos router on dedicated hosts. 或者,您可以将mongos路由器放置在专用主机上。Large deployments benefit from this approach because it decouples the number of client application servers from the number of mongos instances. 大型部署受益于这种方法,因为它将客户机应用程序服务器的数量与mongos实例的数量分离。This gives greater control over the number of connections the mongod instances serve.这样就可以更好地控制mongod实例所服务的连接数。

Installing mongos instances on their own hosts allows these instances to use greater amounts of memory. 在自己的主机上安装mongos实例可以让这些实例使用更多内存。Memory would not be shared with a mongod instance. 内存不会与mongod实例共享。It is possible to use primary shards to host mongos routers but be aware that memory contention may become an issue on large deployments.可以使用主分片来托管mongos路由器,但请注意,在大型部署中,内存争用可能会成为一个问题。

There is no limit to the number of mongos routers you can have in a deployment. 部署中可以拥有的mongos路由器数量没有限制。However, as mongos routers communicate frequently with your config servers, monitor config server performance closely as you increase the number of routers. 但是,由于mongos路由器经常与配置服务器通信,因此在增加路由器数量时,应密切监视配置服务器的性能。If you see performance degradation, it may be beneficial to cap the number of mongos routers in your deployment.如果您发现性能下降,那么在部署中限制mongos路由器的数量可能是有益的。

Diagram of a sample sharded cluster for production purposes.  Contains exactly 3 config servers, 2 or more ``mongos`` query routers, and at least 2 shards. The shards are replica sets.

Development Configuration开发配置

For testing and development, you can deploy a sharded cluster with a minimum number of components. 对于测试和开发,您可以使用最少数量的组件部署分片集群。These non-production clusters have the following components:这些非生产集群具有以下组件:

Diagram of a sample sharded cluster for testing/development purposes only.  Contains only 1 config server, 1 ``mongos`` router, and at least 1 shard. The shard can be either a replica set or a standalone ``mongod`` instance.
Warning警告

Use the test cluster architecture for testing and development only.测试集群架构仅用于测试和开发。

Tip提示
See also: 参阅:
←  ShardingShards →