Mongodb 分片shard管理

²       listshards:列出所有的Shard Server

 

 >use admin

> db.runCommand({listshards:1})
{
        "shards" : [
                {
                        "_id" : "s1",
                        "host" : "shard_liyan1/127.0.0.1:16001,127.0.0.1:16003"
                },
                {
                        "_id" : "s2",
                        "host" : "shard_liyan2/127.0.0.1:16002,127.0.0.1:16004"
                },
                {
                        "_id" : "s3",
                        "host" : "shard_liyan3/127.0.0.1:16010,127.0.0.1:16011"
                }
        ],
        "ok" : 1
}

 

 

²       移除shard

> db.runCommand( { removeshard : "shard_liyan1/127.0.0.1:16001,127.0.0.1:16003" } );{ msg : "draining started successfully" , state: "started" , shard :"localhost:10000" , ok : 1

²       printShardingStatus:查看Sharding信息

 

> printShardingStatus()
--- Sharding Status --- 
  sharding version: { "_id" : 1, "version" : 3 }
  shards:
      { "_id" : "s1", "host" : "shard_liyan1/127.0.0.1:16001,127.0.0.1:16003" }
      { "_id" : "s2", "host" : "shard_liyan2/127.0.0.1:16002,127.0.0.1:16004" }
      { "_id" : "s3", "host" : "shard_liyan3/127.0.0.1:16010,127.0.0.1:16011" }
  databases:
        { "_id" : "admin", "partitioned" : false, "primary" : "config" }
        { "_id" : "ISYDB", "partitioned" : true, "primary" : "s1" }
                ISYDB.VIDEO chunks:
                                s2      95
                                s3      94
                                s1      95
                        too many chunksn to print, use verbose if you want to force printprintShardingStatus();

--- Sharding Status ---

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

  shards:

      { "_id" : "shard0000", "host" : "132.129.31.213:10000" }

      { "_id" : "shard0001", "host" : "132.129.31.213:10011" }

  databases:

       { "_id" : "admin", "partitioned" : false, "primary" : "config" }

       { "_id" : "test", "partitioned" : true, "primary" : "shard0000" }

              test.user chunks:

                            shard0000    1

                     { "_id" : { $minKey : 1 } } -->> { "_id" : { $maxKey : 1 } } on : shard0000 { "t" : 1000, "i" : 0 }

 

 

 

²       db.<collection_name>.stats():查看具体的 Shard 存储信息

> use test;

switched to db test

> db.user.stats();

{

       "sharded" : true,

       "ns" : "test.user",

       "count" : 0,

       "size" : 0,

       "avgObjSize" : NaN,

       "storageSize" : 8192,

       "nindexes" : 1,

       "nchunks" : 1,

       "shards" : {

              "shard0000" : {

                     "ns" : "test.user",

                     "count" : 0,

                     "size" : 0,

                     "storageSize" : 8192,

                     "numExtents" : 1,

                     "nindexes" : 1,

                     "lastExtentSize" : 8192,

                     "paddingFactor" : 1,

                     "flags" : 1,

                     "totalIndexSize" : 8192,

                     "indexSizes" : {

                            "_id_" : 8192

                     },

                     "ok" : 1

              }

       },

       "ok" : 1

}

 


 

 

²    isdbgrid:用来确认当前是否是 Sharding Cluster

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

{ "isdbgrid" : 1, "hostname" : "ossesbwas", "ok" : 1 }

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

{

       "ismaster" : true,

       "msg" : "isdbgrid",

       "maxBsonObjectSize" : 16777216,

       "ok" : 1

}

 

 

  serverStatus

 

> db.runCommand({"serverStatus":1})
{
        "host" : "cctv226:16001",
        "version" : "1.8.3-rc1",
        "process" : "mongod",
        "uptime" : 64008,
        "uptimeEstimate" : 63927,
        "localTime" : ISODate("2011-09-14T02:17:17.976Z"),
        "globalLock" : {//写入锁占用时间
                "totalTime" : 64008240500,
                "lockTime" : 268,
                "ratio" : 4.186960896073999e-9,
                "currentQueue" : {
                        "total" : 0,
                        "readers" : 0,
                        "writers" : 0
                },
                "activeClients" : {
                        "total" : 0,
                        "readers" : 0,
                        "writers" : 0
                }
        },
        "mem" : {//内存使用情况 单位MB
                "bits" : 64,//内存映射了多少硬盘
                "resident" : 4,//常驻内存
                "virtual" : 106,//虚拟内存
                "supported" : true,
                "mapped" : 0
        },
        "connections" : {
                "current" : 2,
                "available" : 19998
        },
        "extra_info" : {
                "note" : "fields vary by platform",
                "heap_usage_bytes" : 567344,
                "page_faults" : 3
        },
        "indexCounters" : {
                "btree" : {
                        "accesses" : 0,
                        "hits" : 0,//内存检索
                        "misses" : 0,//硬盘检索
                        "resets" : 0,
                        "missRatio" : 0//命中率
                }
        },
        "backgroundFlushing" : {
                "flushes" : 1066,
                "total_ms" : 15,
                "average_ms" : 0.014071294559099437,
                "last_ms" : 0,
                "last_finished" : ISODate("2011-09-14T02:16:31.768Z")
        },
        "cursors" : {
                "totalOpen" : 0,
                "clientCursors_size" : 0,
                "timedOut" : 0
        },
        "network" : {
                "bytesIn" : 1279904,
                "bytesOut" : 1957433,
                "numRequests" : 18631
        },
        "repl" : {
                "ismaster" : false,
                "secondary" : false,
                "info" : "can't get local.system.replset config from self or any seed (EMPTYCONFIG)",
                "isreplicaset" : true
        },
        "opcountersRepl" : {
                "insert" : 0,
                "query" : 0,
                "update" : 0,
                "delete" : 0,
                "getmore" : 0,
                "command" : 0
        },
        "opcounters" : {//各种操作的次数
                "insert" : 0,
                "query" : 6402,
                "update" : 0,
                "delete" : 0,
                "getmore" : 0,
                "command" : 12231
        },
        "asserts" : {
                "regular" : 0,
                "warning" : 0,
                "msg" : 0,
                "user" : 1,
                "rollovers" : 0
        },
        "writeBacksQueued" : false,
        "ok" : 1
}

 

 

 bin目录下的命令mongostat (相关说明http://hi.baidu.com/savagert/blog/item/9a14ae95474635137bf48008.html)

 ./mongostat -port 16001
connected to: 127.0.0.1:16001
insert  query update delete getmore command flushes mapped  vsize    res faults locked % idx miss %     qr|qw   ar|aw  netIn netOut  conn repl       time 
    *0     *0     *0     *0       0     1|0       0     0m   106m     4m      0        0          0       0|0     0|0    62b     1k     2  REC   10:36:00 
    *0     *0     *0     *0       0     1|0       0     0m   106m     4m      0        0          0       0|0     0|0    62b     1k     2  REC   10:36:01 
    *0      1     *0     *0       0     2|0       0     0m   106m     4m      0        0          0       0|0     0|0   198b     1k     2  REC   10:36:02 
    *0     *0     *0     *0       0     1|0       0     0m   106m     4m      0        0          0       0|0     0|0    62b     1k     2  REC   10:36:03 
    *0     *0     *0     *0       0     1|0       0     0m   106m     4m      0        0          0       0|0     0|0    62b     1k     2  REC   10:36:04 
    *0     *0     *0     *0       0     1|0       0     0m   106m     4m      0        0          0       0|0     0|0    62b    db.runCommand({isdbgrid:1});