MongoDB分布式操作――分片操作(五)

2014-11-24 11:35:21 · 作者: · 浏览: 5
01" }
{ "_id" : "shard0002", "host" : "localhost:10002" }
mongos>
(10)查看databases集合:
[plain]
mongos> db.databases.find();
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "foo", "partitioned" : true, "primary" : "shard0000" }
mongos>
(11) 查看chucks集合:
[plain]
mongos> db.chunks.find();
{ "_id" : "foo.bar-_id_MinKey", "lastmod" : Timestamp(1, 0), "lastmodEpoch" : ObjectId("52087d0a1072e2912d4242ea"), "ns" : "foo.bar", "min" : { "_id" : { "$minKey" : 1 } }, "max" : { "_id" : { "$maxKey" : 1 } }, "shard" : "shard0000" }
mongos>
(12)获得概要信息:
[plain]
mongos> db.printShardingStatus();
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 3,
"minCompatibleVersion" : 3,
"currentVersion" : 4,
"clusterId" : ObjectId("52087bf41072e2912d4242b8")
}
shards:
{ "_id" : "shard0000", "host" : "localhost:10000" }
{ "_id" : "shard0001", "host" : "localhost:10001" }
{ "_id" : "shard0002", "host" : "localhost:10002" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "foo", "partitioned" : true, "primary" : "shard0000" }
foo.bar
shard key: { "_id" : 1 }
chunks:
shard0000 1
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 0)
mongos>
(13)移除分片:
[plain]
mongos> use admin
switched to db admin
mongos> db.runCommand({"removeshard" : "localhost:10000"});
{
"msg" : "draining started successfully",
"state" : "started",
"shard" : "shard0000",
"note" : "you need to drop or movePrimary these databases",
"dbsToMove" : [
"foo"
],
"ok" : 1
}
mongos>
总结:对MongoDB的分片操作执行如下顺序:
(1)启动配置服务器;
(2)启动mongos进程;
(3)添加mongo实例(片);
(4)对数据库或者数据集使用分片操作。