2

查看 MongoDB 集群配置

 2 years ago
source link: https://mongoing.com/archives/80264
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

本文介绍查看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" }

原文链接:

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

译者:张冲

MongoDB中文社区翻译小组成员,对软件工程、多媒体设计、数据库编程、程序设计方面有多年的工作经验。具有较强的网络管理知识和实践经验,现主要从事网络安全相关工作,兴趣是从事大数据分析工作。

添加小芒果微信(ID:mongingcom)进入中文用户组技术交流群。

来这里,点亮自己!


MongoDB中文社区技术大会议题征集中,打开链接来这里分享经验与见解——

https://sourl.cn/f7Bgsf

活动资料发布消息订阅:

https://sourl.cn/DgdiNd

点击申请加入核心用户组:

https://sourl.cn/u8W8FU

获取MongoDB免费线上培训入口及配套资料:

https://sourl.cn/EtVUrP

我们还将在上海广州深圳南京成都等城市举办技术大会,有合作意向请提前联系小芒果微信或社区核心成员。

 

MongoDB-全球领先的现代通用数据库

长按二维码关注我们

Mongoing中文社区

MongoDB中文社区微信公众号

扫描关注,获取更多精彩内容

社区网站www.mongoing.com




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK