檢視 MongoDB 叢集配置

語言: CN / TW / HK

本文介紹檢視MongoDB叢集配置方法。

列出開啟分片的資料庫 

查詢配置資料庫中的 databases 集合,可以列出已開啟分片功能的資料庫列表。

如果一個數據庫中 partitioned 欄位的值為 true ,則該資料庫已開啟分片功能。

使用mongo shell連線到一個 mongos 例項,執行以下命令獲取一個完整的已開啟分片的資料庫列表:

use config

db.databases.find( { "partitioned": true } )

示例

可以使用如下命令返回叢集中的所有資料庫列表:

use config
db.databases.find()

如果上述命令返回如下結果集:

{ "_id" : "test", "primary" : "shardB", "partitioned" : false }

{ "_id" : "animals", "primary" : "shardA", "partitioned" : true }
{ "_id" : "farms", "primary" : "shardA", "partitioned" : false }

那麼只有 animals 資料庫是已分片的。

列出分片 

使用 listShards 命令,列出當前已配置的分片:

db.adminCommand( { listShards : 1 } )

檢視 MongoDB 叢集詳情 

使用 db.printShardingStatus() 或者  sh.status() 可以檢視叢集的詳情。這兩個命令會返回同樣的結果。

示例

以下示例的輸出結果來自sh.status()

  • sharding version 顯示了分片元資料的版本號
  • shards 顯示了作為叢集分片的 mongod 例項列表。
  • databases 顯示了叢集中的所有資料庫,包括未開啟分片的資料庫。
  • foo 資料庫的 chunks 資訊,顯示了每個分片上有多少個數據塊,以及每個資料塊的範圍。
--- Sharding Status ---
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("59a4443c3d38cd8a0b40316d")
  }
  shards:
    {  "_id" : "shard0000",  "host" : "m0.example.net:27018" }
    {  "_id" : "shard0001",  "host" : "m3.example2.net:27018" }
    {  "_id" : "shard0002",  "host" : "m2.example.net:27018" }
  active mongoses:
    "3.4.7" : 1
  autosplit:
    Currently enabled: yes
   balancer:
    Currently enabled:  yes
    Currently running:  no
    Failed balancer rounds in last 5 attempts:  0
    Migration Results for the last 24 hours:
       1 : Success
  databases:
    {  "_id" : "foo",  "partitioned" : true,  "primary" : "shard0000" }
        foo.contacts
            shard key: { "zip" : 1 }
            unique: false
            balancing: true
            chunks:
                shard0001    2
                shard0002    3
                shard0000    2
            { "zip" : { "$minKey" : 1 } } -->> { "zip" : "56000" } on : shard0001 { "t" : 2, "i" : 0 }
            { "zip" : 56000 } -->> { "zip" : "56800" } on : shard0002 { "t" : 3, "i" : 4 }
            { "zip" : 56800 } -->> { "zip" : "57088" } on : shard0002 { "t" : 4, "i" : 2 }
            { "zip" : 57088 } -->> { "zip" : "57500" } on : shard0002 { "t" : 4, "i" : 3 }
            { "zip" : 57500 } -->> { "zip" : "58140" } on : shard0001 { "t" : 4, "i" : 0 }
            { "zip" : 58140 } -->> { "zip" : "59000" } on : shard0000 { "t" : 4, "i" : 1 }
            { "zip" : 59000 } -->> { "zip" : { "$maxKey" : 1 } } on : shard0000 { "t" : 3, "i" : 3 }
    {  "_id" : "test",  "partitioned" : false,  "primary" : "shard0000" }

原文連結:

http://docs.mongodb.com/manual/tutorial/view-sharded-cluster-configuration/

譯者:張衝

MongoDB中文社群翻譯小組成員,對軟體工程、多媒體設計、資料庫程式設計、程式設計方面有多年的工作經驗。具有較強的網路管理知識和實踐經驗,現主要從事網路安全相關工作,興趣是從事大資料分析工作。

新增小芒果微信(ID:mongingcom)進入中文使用者組技術交流群。

來這裡,點亮自己!

MongoDB中文社群技術大會議題徵集中,開啟連結來這裡分享經驗與見解——

http://sourl.cn/f7Bgsf

活動資料釋出訊息訂閱:

http://sourl.cn/DgdiNd

點選申請加入核心使用者組:

http://sourl.cn/u8W8FU

獲取MongoDB免費線上培訓入口及配套資料:

http://sourl.cn/EtVUrP

我們還將在上海廣州深圳南京成都等城市舉辦技術大會,有合作意向請提前聯絡小芒果微信或社群核心成員。

長按二維碼關注我們

Mongoing中文社群

MongoDB中文社群微信公眾號

掃描關注,獲取更多精彩內容

社群網站www.mongoing.com