MongoDB实战系列之六(2):mongodb的高可用集群设计实战

  在分片后新写数据第一次:
mongos> db.elain.stats();
{
"sharded" : true,
"flags" : 1,
"ns" : "elain.elain",
"count" : 676496,
"numExtents" : 12,
"size" : 112500436,
"storageSize" : 129179648,
"totalIndexSize" : 47551616,
"indexSizes" : {
"_id_" : 21968912,
"client_userid_1" : 25582704
},
"avgObjSize" : 166.29874529930703,
"nindexes" : 2,
"nchunks" : 8,
"shards" : {
"shard1" : {
"ns" : "elain.elain",
"count" : 0,
"size" : 0,
"storageSize" : 8192,
"numExtents" : 1,
"nindexes" : 2,
"lastExtentSize" : 8192,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 16352,
"indexSizes" : {
"_id_" : 8176,
"client_userid_1" : 8176
},
"ok" : 1
},
"shard2" : {
"ns" : "elain.elain",
"count" : 676496,
"size" : 112500436,
"avgObjSize" : 166.29874529930703,
"storageSize" : 129171456,
"numExtents" : 11,
"nindexes" : 2,
"lastExtentSize" : 31322112,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 47535264,
"indexSizes" : {
"_id_" : 21960736,
"client_userid_1" : 25574528
},
"ok" : 1
}
},
"ok" : 1
}
分片后新写数据第二次:
mongos> db.elain.stats();
{
"sharded" : true,
"flags" : 1,
"ns" : "elain.elain",
"count" : 1189194,
"numExtents" : 23,
"size" : 194533928,
"storageSize" : 252874752,
"totalIndexSize" : 87262448,
"indexSizes" : {
"_id_" : 43692544,
"client_userid_1" : 43569904
},
"avgObjSize" : 163.58468677103988,
"nindexes" : 2,
"nchunks" : 8,
"shards" : {
"shard1" : {
"ns" : "elain.elain",
"count" : 396370,
"size" : 62195348,
"avgObjSize" : 156.91234957236924,
"storageSize" : 86114304,
"numExtents" : 11,
"nindexes" : 2,
"lastExtentSize" : 20881408,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 35949872,
"indexSizes" : {
"_id_" : 17954496,
"client_userid_1" : 17995376
},
"ok" : 1
},
"shard2" : {
"ns" : "elain.elain",
"count" : 792824,
"size" : 132338580,
"avgObjSize" : 166.9205019020615,
"storageSize" : 166760448,
"numExtents" : 12,
"nindexes" : 2,
"lastExtentSize" : 37588992,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 51312576,
"indexSizes" : {
"_id_" : 25738048,
"client_userid_1" : 25574528
},
"ok" : 1
}
},
"ok" : 1
}
分片后新写数据第三次:
 
mongos> db.elain.stats();
{
"sharded" : true,
"flags" : 1,
"ns" : "elain.elain",
"count" : 1376876,
"numExtents" : 23,
"size" : 225576604,
"storageSize" : 252874752,
"totalIndexSize" : 100826432,
"indexSizes" : {
"_id_" : 50249696,
"client_userid_1" : 50576736
},
"avgObjSize" : 163.83218532387812,
"nindexes" : 2,
"nchunks" : 10,
"shards" : {
"shard1" : {
"ns" : "elain.elain",
"count" : 494202,
"size" : 77551984,
"avgObjSize" : 156.92365469990003,
"storageSize" : 86114304,
"numExtents" : 11,
"nindexes" : 2,
"lastExtentSize" : 20881408,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 42057344,
"indexSizes" : {
"_id_" : 21600992,
"client_userid_1" : 20456352
},
"ok" : 1
},
"shard2" : {
"ns" : "elain.elain",
"count" : 882674,
"size" : 148024620,
"avgObjSize" : 167.70021548159343,
"storageSize" : 166760448,
"numExtents" : 12,
"nindexes" : 2,
"lastExtentSize" : 37588992,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 58769088,
"indexSizes" : {
"_id_" : 28648704,
"client_userid_1" : 30120384
},
"ok" : 1
}
},
"ok" : 1
}
分片后新写数据第四次(DOWN 掉md04的mongo服务)
 
mongos> db.elain.stats();
{
"sharded" : true,
"flags" : 1,
"ns" : "elain.elain",
"count" : 1686310,
"numExtents" : 26,
"size" : 275761376,
"storageSize" : 353116160,
"totalIndexSize" : 129033632,
"indexSizes" : {
"_id_" : 63265888,
"client_userid_1" : 65767744
},
"avgObjSize" : 163.52946729842083,
"nindexes" : 2,
"nchunks" : 10,
"shards" : {
"shard1" : {
"ns" : "elain.elain",
"count" : 740264,
"size" : 116213588,
"avgObjSize" : 156.98938216636228,
"storageSize" : 141246464,
"numExtents" : 13,
"nindexes" : 2,
"lastExtentSize" : 30072832,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 61810560,
"indexSizes" : {
"_id_" : 32556832,
"client_userid_1" : 29253728
},
"ok" : 1
},
"shard2" : {
"ns" : "elain.elain",
"count" : 946046,
"size" : 159547788,
"avgObjSize" : 168.64696642657967,
"storageSize" : 211869696,
"numExtents" : 13,
"nindexes" : 2,
"lastExtentSize" : 45109248,
"paddingFactor" : 1,
"flags" : 1,
"totalIndexSize" : 67223072,
"indexSizes" : {
"_id_" : 30709056,
"client_userid_1" : 36514016
},
"ok" : 1
}
},
"ok" : 1
}
总结:通过以上四次的写数据测试,我们可以看到分片是成功的,每次写数据,shard1、shard2都有数据写入,且,在下面的复制集中DOWN 掉任意一台,不影响整个架构的正常服务。
 
删除片操作
 
mongos> db.runCommand({"removeshard" : "10.0.0.11:27011"});
{
"msg" : "draining started successfully",
"state" : "started",
"shard" : "shard2",
"ok" : 1
}
再执行,可看到removeshard的挪动进度
mongos> db.runCommand({"removeshard" : "10.0.0.11:27011"});
{
"msg" : "draining ongoing",
"state" : "ongoing",
"remaining" : {
"chunks" : NumberLong(3),
"dbs" : NumberLong(0)
},
"ok" : 1
}
到此结束

你可能感兴趣的:(MongoDB实战)