Nosql Mongodb之旅(28)—MongoDB管理维护Sharding
2014-04-21 20:33
399 查看
1、列出所有的Shard Server
[plain] view
plaincopy
> db.runCommand({ listshards: 1 }) --列出所有的Shard Server
{
"shards" : [
{
"_id" : "shard0000",
"host" : "localhost:20000"
},
{
"_id" : "shard0001",
"host" : "localhost:20001"
}
],
"ok" : 1
}
2、查看Sharding信息
[plain] view
plaincopy
> printShardingStatus() --查看Sharding 信息
--- Sharding Status ---
sharding version: { "_id" : 1, "version" : 3 }
shards:
{ "_id" : "shard0000", "host" : "localhost:20000" }
{ "_id" : "shard0001", "host" : "localhost:20001" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }
test.users chunks:
shard0000 1
{ "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } } on :
shard0000 { "t" : 1000, "i" : 0 }
>
3、判断是否是Sharding
[plain] view
plaincopy
> db.runCommand({ isdbgrid:1 })
{ "isdbgrid" : 1, "hostname" : "localhost", "ok" : 1 }
>
4、对现有的集合进行分片(实例)
刚才我们是对表test.users 进行分片了,下面我们将对库中现有的未分片的表test.users_2 进行分片处理。
表最初状态如下,可以看出他没有被分片过:
[plain] view
plaincopy
> db.users_2.stats()
{
"ns" : "test.users_2",
"sharded" : false,
"primary" : "shard0000",
"ns" : "test.users_2",
"count" : 500000,
"size" : 48000016,
"avgObjSize" : 96.000032,
"storageSize" : 61875968,
"numExtents" : 11,
"nindexes" : 1,
"lastExtentSize" : 15001856,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 20807680,
"indexSizes" : {
"_id_" : 20807680
},
"ok" : 1
}
对其进行分片处理:
[plain] view
plaincopy
> use admin
switched to db admin
> db.runCommand({ shardcollection: "test.users_2", key: { _id:1 }})
{ "collectionsharded" : "test.users_2", "ok" : 1 }
再次查看分片后的表的状态,可以看到它已经被我们分片了
[plain] view
plaincopy
> use test
switched to db test
> db.users_2.stats()
{
"sharded" : true,
"ns" : "test.users_2",
"count" : 505462,
……
"shards" : {
"shard0000" : {
"ns" : "test.users_2",
……
"ok" : 1
},
"shard0001" : {
"ns" : "test.users_2",
……
"ok" : 1
}
},
"ok" : 1
}
>
[plain] view
plaincopy
> db.runCommand({ listshards: 1 }) --列出所有的Shard Server
{
"shards" : [
{
"_id" : "shard0000",
"host" : "localhost:20000"
},
{
"_id" : "shard0001",
"host" : "localhost:20001"
}
],
"ok" : 1
}
2、查看Sharding信息
[plain] view
plaincopy
> printShardingStatus() --查看Sharding 信息
--- Sharding Status ---
sharding version: { "_id" : 1, "version" : 3 }
shards:
{ "_id" : "shard0000", "host" : "localhost:20000" }
{ "_id" : "shard0001", "host" : "localhost:20001" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }
test.users chunks:
shard0000 1
{ "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } } on :
shard0000 { "t" : 1000, "i" : 0 }
>
3、判断是否是Sharding
[plain] view
plaincopy
> db.runCommand({ isdbgrid:1 })
{ "isdbgrid" : 1, "hostname" : "localhost", "ok" : 1 }
>
4、对现有的集合进行分片(实例)
刚才我们是对表test.users 进行分片了,下面我们将对库中现有的未分片的表test.users_2 进行分片处理。
表最初状态如下,可以看出他没有被分片过:
[plain] view
plaincopy
> db.users_2.stats()
{
"ns" : "test.users_2",
"sharded" : false,
"primary" : "shard0000",
"ns" : "test.users_2",
"count" : 500000,
"size" : 48000016,
"avgObjSize" : 96.000032,
"storageSize" : 61875968,
"numExtents" : 11,
"nindexes" : 1,
"lastExtentSize" : 15001856,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 20807680,
"indexSizes" : {
"_id_" : 20807680
},
"ok" : 1
}
对其进行分片处理:
[plain] view
plaincopy
> use admin
switched to db admin
> db.runCommand({ shardcollection: "test.users_2", key: { _id:1 }})
{ "collectionsharded" : "test.users_2", "ok" : 1 }
再次查看分片后的表的状态,可以看到它已经被我们分片了
[plain] view
plaincopy
> use test
switched to db test
> db.users_2.stats()
{
"sharded" : true,
"ns" : "test.users_2",
"count" : 505462,
……
"shards" : {
"shard0000" : {
"ns" : "test.users_2",
……
"ok" : 1
},
"shard0001" : {
"ns" : "test.users_2",
……
"ok" : 1
}
},
"ok" : 1
}
>
相关文章推荐
- MongoDB学习之旅二十七:MongoDB 管理维护Sharding
- 第九章:MongoDB管理维护sharding
- mongodb sharding maintenance (分片维护1)
- MongoDB的日常维护管理(不错)
- 转 -- Mongodb管理与维护手册
- 第九章:管理维护sharding
- MongoDB学习之旅二十三:管理维护 Replica Sets
- MongoDB管理与开发精要《红丸出品》22.6 Sharding分片之管理维护
- MySQL,Oracle,PostgreSQL,mongoDB 通过web方式管理维护, 提高开发及运维效率
- 第七章:MongoDB管理维护Replica Sets(读写分离&故障转移&增删节点)
- 单机环境下构建和管理 MongoDB sharding 分片集步骤
- MongoDB的日常维护管理
- MongoDB 可视化管理工具 MongoCola-1.0.4发布
- 【MongoDB-MongoVUE图像管理工具】
- MongoDB用户管理
- Linux常用命令笔记--逻辑卷管理与维护
- MongoDB基本管理命令
- ScriptCase开发平台介绍(五)——管理和维护项目
- 菠菜程序修复 mongodb的sharding集群搭建
- SSIS ->> 管理和维护SSISDB