`
chakey
  • 浏览: 359619 次
  • 性别: Icon_minigender_1
  • 来自: 水星
社区版块
存档分类
最新评论

【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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics