Chinaunix首页 | 论坛 | 博客
  • 博客访问: 273407
  • 博文数量: 52
  • 博客积分: 120
  • 博客等级: 民兵
  • 技术积分: 1189
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-03 15:41
个人简介

MySQL DBA

文章分类

全部博文(52)

文章存档

2013年(51)

2011年(1)

分类: NOSQL

2013-03-07 14:03:02

mongodb 分区

mongodb的自动sharding 功能:自动切分数据和平衡数据分配。

shard key:用于分区的key。对于应用的sql(查询及更改),mongos将根据其条件与shard key选择发送查询到指定server或发送给所有的server并合并返回结果集。

shard  数据节点,存储分区数据,可以single server,也可以是复制结构或者replica set

mongos 路由节点,接受并分发客户端的请求到shard server,并合并结果集。                不存储数据和配置信息。

config server      配置节点。存储集群的数据切分信息,mongos通过同步并缓存配置信息进行路由分发。

配置:

1.     启动config servermongosconfig server 必须先启动

config server:     ./mongod --dbpath /storage/mongos-data/ --port 20000

mongos:              ./mongos --port 30000 --configdb localhost:20000

2.     添加mongod 到集群配置中。

mongo --port 30000/admin

mongos> db.runCommand({addshar : "localhost:27017",allowLocal:true})

mongos> db.runCommand({addshard : "localhost:10000",allowLocal:true})

mongos> db.runCommand( { listshards : 1 } )

{

"shards" : [

        {

               "_id" : "shard0000",

               "host" : "localhost:27017"

        },

        {

               "_id" : "shard0001",

               "host" : "localhost:10000"

        },

        {

               "_id" : "shard0002",

               "host" : "localhost:10001"

        }

],

"ok" : 1

}

 

3.切分数据。use admin

mongos> db.runCommand({enablesharding:"shardtest"})

mongos>db.runCommand({“shardcollection”:”shardtest.test”,”key”:{“_id”:1}})

 

阅读(2432) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~