A MongoDB sharded cluster consists of the following components:MongoDB分片集群由以下组件组成:
shard: Each shard contains a subset of the sharded data. Each shard must be deployed as a replica set.分片:每个分片都包含分片数据的一个子集。每个分片都必须部署为副本集。Routing with mongos: The使用mongosacts as a query router, providing an interface between client applications and the sharded cluster.mongos进行路由:mongos充当查询路由器,在客户端应用程序和分片集群之间提供接口。config servers: Config servers store metadata and configuration settings for the cluster. Config servers must be deployed as a replica set (CSRS).配置服务器:配置服务器存储集群的元数据和配置设置。配置服务器必须作为副本集(CSRS)部署。
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部署一个或多个mongosroutersmongos路由器
Replica Set Distribution副本集分发
For production deployments, we recommend deplying config server and shard replica sets on at least three data centers. This configuration provides high availability in case a single data center goes down.对于生产部署,我们建议将配置服务器和分片副本集部署在至少三个数据中心上。此配置可在单个数据中心发生故障时提供高可用性。
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的数量和分布
mongos and Distributionmongos routers support high availability and scalability when deploying multiple mongos instances. mongos路由器在部署多个mongos实例时支持高可用性和可扩展性。If a proxy or load balancer is between the application and the 如果代理或负载平衡器位于应用程序和mongos routers, you must configure it for client affinity. mongos路由器之间,则必须对其进行客户端关联配置。Client affinity allows every connection from a single client to reach the same 客户端亲和性允许来自单个客户端的每个连接到达相同的mongos. For shard-level high availability, either:mongos。要获得分片级别的高可用性,请执行以下任一操作:
Add在已经运行mongosinstances on the same hardware wheremongodinstances are already running.mongod实例的同一硬件上添加mongos实例。Embed将mongosrouters on the same hardware where the application is hosted.mongos路由器嵌入到托管应用程序的同一硬件上。
mongos routers communicate frequently with your config servers. As you increase the number of routers, performance may degrade. If performance degrades, reduce the number of routers.mongos路由器经常与您的配置服务器通信。随着路由器数量的增加,性能可能会下降。如果性能下降,请减少路由器的数量。
The following diagram shows a common sharded cluster architecture used in production:下图显示了生产中使用的常见分片集群架构:

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:对于测试和开发,您可以部署一个具有最少组件数量的分片集群。这些非生产集群有以下组成部分:
One一个mongosinstance.mongos实例。A single shard replica set.单个分片副本集。A replica set config server.副本集配置服务器。
The following diagram shows a sharded cluster architecture used for development only:下图显示了仅用于开发的分片集群架构:

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