【7】MongoDB分片管理(Sharding Administration)

 

【7】MongoDB分片管理(Sharding Administration)

下面介绍几个非常有用的命令,可以获取一个分片集群的一些配置信息。

关于如何配置分片请查看:

http://datalife.iteye.com/blog/805201

 

一:如果判断是否是分片集群?

// Test if we're speaking to a mongos process or 

// straight to a mongod process

> db.runCommand({ isdbgrid : 1});

 

// if connected to mongos, this command returns { ismaster: 0.0, msg: "isdbgrid" }

> db.runCommand({ismaster:1});

 

二:如何列举出所有存在的分片?

> db.runCommand({ listShards : 1});

{"servers" :

 [{"_id" :  ObjectId( "4a9d40c981ba1487ccfaa634")  ,

   "host" : "localhost:10000"},

  {"_id" :  ObjectId( "4a9d40df81ba1487ccfaa635")  ,

   "host" : "localhost:10001"}

 ],

 "ok" : 1

}

 

三:如何列举出哪些数据库被分片了?

这里我们需要查询config 数据库,getSisterDB命令用于返回config数据库。

> config = db.getSisterDB("config")

> config.system.namespaces.find()

 

四:如果查看分片的详细信息?

> use admin

> db.printShardingStatus();

 

// A very basic sharding configuration on localhost

sharding version: { "_id" : 1, "version" : 2 }

  shards:

      { "_id" : ObjectId("4bd9ae3e0a2e26420e556876"), "host" : "localhost:30001" }

      { "_id" : ObjectId("4bd9ae420a2e26420e556877"), "host" : "localhost:30002" }

      { "_id" : ObjectId("4bd9ae460a2e26420e556878"), "host" : "localhost:30003" }

 

  databases:

{ "name" : "admin", "partitioned" : false, 

          "primary" : "localhost:20001", 

          "_id" : ObjectId("4bd9add2c0302e394c6844b6") }

my chunks

        { "name" : "foo", "partitioned" : true,

          "primary" : "localhost:30002", 

          "sharded" : { "foo.foo" : { "key" : { "_id" : 1 }, "unique" : false } },

          "_id" : ObjectId("4bd9ae60c0302e394c6844b7") }

        my chunks

        foo.foo { "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } } 

                  on : localhost:30002 { "t" : 1272557259000, "i" : 1 }

 

第一个数据库是主数据库(admin database),没有分区,位于config服务器,端口20001.

第二个数据库,有分区,因为foo数据库没有数据,所有只有一个块(chunk)。

 

五:块操作(chunk operations)

MongoDB 1.6版本的是可以自动的控制块的大小的,当然也是可以手动调整的。

db.runCommand( { moveChunk : "test.blog.posts" , 

                 find : { author : "eliot" } , 

                 to : "shard1" } )

三个参数:

movechunk:包含数据库名称的全命名空间的collection

find: 属于将被移动的块的查询语句

to: 将被移动的块的shard id

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值