MongoDB学习札记 第九篇 分片核心概念

分片集群的组成

Shards

A shard is a MongoDB instance that holds a subset of a collection’s data. Each shard is either a single mongod instance or a replica set. In production, all shards are replica sets.

Config Servers

Each config server is a mongod instance that holds metadata about the cluster. The metadata maps chunks to shards.

Routing Instances

Each router is a mongos instance that routes the reads and writes from applications to the shards. Applications do not access the shards directly.

为什么使用分片

  • 当本地磁盘不足的时候
  • 请求量巨大导致内存爆满的情况
  • 一台单独的mongod进程无法满足写的需求的情况

重要

部署分片集群是很花时间和资源的。如果你的系统已经能够达到或者超过了他的容量,那时候再去部署分片很难不影响到你现有的应用。

所以如果你觉得你的数据库在不久的将来需要进行分片,那么不要等到你的系统超过本身的承载能力的时候再去分片。

当你设计数据模型的时候,考虑分片的需求吧。

生产环境和测试环境 架构区别

生产环境下

  • 配置服务器:三个配置服务并且每个配置服务都在不同的机器上,这样能够确保安全,三台配置服务也不一定是replica set的形式。可以是单独的三个mongod进程组成。

  • 分片:生成环境下的分片采用Replica Set的形式。至少两个分片。

  • Mongos实例:至少一个mongos进程。

测试环境或者开发环境

  • 一个配置服务器(一个mongod进程)
  • 至少一个分片(分片可以是单独的mongod进程或者 replica set == 一组mongod进程)
  • 一个mongos实例(一个mongos实例最好对应一个应用容器 == 比如一台servlet容器的话,就相应的部署一个mongos实例)

<<< 捐赠 >>>

转载请注明出处! 原文地址: http://webinglin.github.io

Reference:

http://docs.mongodb.org/manual/core/sharding-introduction/

留言

2015-06-10