【Mongodb】 Mongodb sharding 管理之二

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介: shard 集群的系统信息也是保留在config数据库的集合里面的。本文介绍一些Shard 的配置信息查询,mongos> use configswitched to db config查询当前的版本mongos> db.
shard 集群的系统信息也是保留在config数据库的集合里面的。 本文介绍一些Shard 的配置信息查询,
mongos> use config
switched to db config
查询当前的版本
mongos> db.getCollection("version").findOne()
{ "_id" : 1, "version" : 3 }
查询当前的配置chunkSize的大小
mongos> db.settings.find()
{ "_id" : "chunksize", "value" : 1 }
查询整个shard集群的成员
mongos> db.shards.find()
{ "_id" : "shard0000", "host" : "10.250.7.225:27018" }
{ "_id" : "shard0001", "host" : "10.250.7.249:27019" }
{ "_id" : "shard0002", "host" : "10.250.7.241:27020" }
查询被水平拆分的集合:
mongos>  db.collections.find()
{ "_id" : "test.yql", "lastmod" : ISODate("1970-01-16T06:45:27.212Z"), "dropped" : false, "key" : { "_id" : 1 }, "unique" : true }
查询被水平拆分的集合分成的chunk分布
mongos> db.chunks.find()
{ "_id" : "test.yql-_id_MinKey", "lastmod" : { "t" : 2000, "i" : 1 }, "ns" : "test.yql", "min" : { "_id" : { $minKey : 1 } }, "max" : { "_id" : ObjectId("4eb298b3adbd9673afee95e3") }, "shard" : "shard0000" }
{ "_id" : "test.yql-_id_ObjectId('4eb298b3adbd9673afee95e3')", "lastmod" : { "t" : 1000, "i" : 3 }, "ns" : "test.yql", "min" : { "_id" : ObjectId("4eb298b3adbd9673afee95e3") }, "max" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "shard" : "shard0000" }
{ "_id" : "test.yql-_id_ObjectId('4eb2a64640643e5bb60072f7')", "lastmod" : { "t" : 3000, "i" : 1 }, "ns" : "test.yql", "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : ObjectId("4eb2a65340643e5bb600e084") }, "shard" : "shard0002" }
{ "_id" : "test.yql-_id_ObjectId('4eb2a65340643e5bb600e084')", "lastmod" : { "t" : 3000, "i" : 0 }, "ns" : "test.yql", "min" : { "_id" : ObjectId("4eb2a65340643e5bb600e084") }, "max" : { "_id" : { $maxKey : 1 } }, "shard" : "shard0001" }
查询当前mongodb里面的数据库的shard信息:
mongos> db.databases.find()
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : true, "primary" : "shard0000" }
{ "_id" : "mongos", "partitioned" : false, "primary" : "shard0000" }
mongos集合记录的这个集群中的所有mongos服务,默认每隔30s钟ping mongos服务器一次,以便查看其是否alive。
mongos> db.mongos.find()
{ "_id" : "rac4:27017", "ping" : ISODate("2011-11-05T05:47:50.575Z"), "up" : 145503 }
changlog 集合
记录了sharding 集群的元数据,changlog 默认记录10M的操作。
mongos> db.changelog.findOne()
{
        "_id" : "rac1-2011-11-03T14:42:14-0",
        "server" : "rac1",
        "clientAddr" : "10.250.7.220:53899",
        "time" : ISODate("2011-11-03T14:42:14.873Z"),
        "what" : "split",
        "ns" : "test.yql",
        "details" : {
                "before" : {
                        "min" : {
                                "_id" : { $minKey : 1 }
                        },
                        "max" : {
                                "_id" : { $maxKey : 1 }
                        },
                        "lastmod" : {
                                "t" : 1000,
                                "i" : 0
                        }
                },
                "left" : {
                        "min" : {
                                "_id" : { $minKey : 1 }
                        },
                        "max" : {
                                "_id" : ObjectId("4eb298b3adbd9673afee95e3")
                        },
                        "lastmod" : {
                                "t" : 1000,
                                "i" : 1
                        }
                },
                "right" : {
                        "min" : {
                                "_id" : ObjectId("4eb298b3adbd9673afee95e3")
                        },
                        "max" : {
                                "_id" : { $maxKey : 1 }
                        },
                        "lastmod" : {
                                "t" : 1000,
                                "i" : 2
                        }
                }
        }
}
mongos> db.changelog.find()
{ "_id" : "rac1-2011-11-03T14:42:14-0", "server" : "rac1", "clientAddr" : "10.250.7.220:53899", "time" : ISODate("2011-11-03T14:42:14.873Z"), "what" : "split", "ns" : "test.yql", "details" : { "before" : { "min" : { "_id" : { $minKey : 1 } }, "max" : { "_id" : { $maxKey : 1 } }, "lastmod" : { "t" : 1000, "i" : 0 } }, "left" : { "min" : { "_id" : { $minKey : 1 } }, "max" : { "_id" : ObjectId("4eb298b3adbd9673afee95e3") }, "lastmod" : { "t" : 1000, "i" : 1 } }, "right" : { "min" : { "_id" : ObjectId("4eb298b3adbd9673afee95e3") }, "max" : { "_id" : { $maxKey : 1 } }, "lastmod" : { "t" : 1000, "i" : 2 } } } }
{ "_id" : "rac1-2011-11-03T14:42:16-1", "server" : "rac1", "clientAddr" : "10.250.7.220:53899", "time" : ISODate("2011-11-03T14:42:16.294Z"), "what" : "split", "ns" : "test.yql", "details" : { "before" : { "min" : { "_id" : ObjectId("4eb298b3adbd9673afee95e3") }, "max" : { "_id" : { $maxKey : 1 } }, "lastmod" : { "t" : 1000, "i" : 2 } }, "left" : { "min" : { "_id" : ObjectId("4eb298b3adbd9673afee95e3") }, "max" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "lastmod" : { "t" : 1000, "i" : 3 } }, "right" : { "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : { $maxKey : 1 } }, "lastmod" : { "t" : 1000, "i" : 4 } } } }
{ "_id" : "rac1-2011-11-03T14:42:16-2", "server" : "rac1", "clientAddr" : "10.250.7.220:53899", "time" : ISODate("2011-11-03T14:42:16.460Z"), "what" : "moveChunk.start", "ns" : "test.yql", "details" : { "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : { $maxKey : 1 } }, "from" : "shard0000", "to" : "shard0002" } }
{ "_id" : "rac1-2011-11-03T14:42:21-3", "server" : "rac1", "clientAddr" : "10.250.7.220:53899", "time" : ISODate("2011-11-03T14:42:21.544Z"), "what" : "moveChunk.commit", "ns" : "test.yql", "details" : { "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : { $maxKey : 1 } }, "from" : "shard0000", "to" : "shard0002" } }
{ "_id" : "rac3-2011-11-03T14:42:21-0", "server" : "rac3", "clientAddr" : "", "time" : ISODate("2011-11-03T14:42:21.513Z"), "what" : "moveChunk.to", "ns" : "test.yql", "details" : { "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : { $maxKey : 1 } }, "step1" : 3604, "step2" : 982, "step3" : 1, "step4" : 0, "step5" : 423 } }
{ "_id" : "rac1-2011-11-03T14:42:21-4", "server" : "rac1", "clientAddr" : "10.250.7.220:53899", "time" : ISODate("2011-11-03T14:42:21.686Z"), "what" : "moveChunk.from", "ns" : "test.yql", "details" : { "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : { $maxKey : 1 } }, "step1" : 0, "step2" : 121, "step3" : 8, "step4" : 5005, "step5" : 69, "step6" : 29 } }
{ "_id" : "rac3-2011-11-03T14:42:29-1", "server" : "rac3", "clientAddr" : "10.250.7.220:11131", "time" : ISODate("2011-11-03T14:42:29.819Z"), "what" : "split", "ns" : "test.yql", "details" : { "before" : { "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : { $maxKey : 1 } }, "lastmod" : { "t" : 2000, "i" : 0 } }, "left" : { "min" : { "_id" : ObjectId("4eb2a64640643e5bb60072f7") }, "max" : { "_id" : ObjectId("4eb2a65340643e5bb600e084") }, "lastmod" : { "t" : 2000, "i" : 2 } }, "right" : { "min" : { "_id" : ObjectId("4eb2a65340643e5bb600e084") }, "max" : { "_id" : { $maxKey : 1 } }, "lastmod" : { "t" : 2000, "i" : 3 } } } }
{ "_id" : "rac3-2011-11-03T14:42:30-2", "server" : "rac3", "clientAddr" : "10.250.7.220:11131", "time" : ISODate("2011-11-03T14:42:30.103Z"), "what" : "moveChunk.start", "ns" : "test.yql", "details" : { "min" : { "_id" : ObjectId("4eb2a65340643e5bb600e084") }, "max" : { "_id" : { $maxKey : 1 } }, "from" : "shard0002", "to" : "shard0001" } }
{ "_id" : "rac3-2011-11-03T14:44:15-3", "server" : "rac3", "clientAddr" : "10.250.7.220:11131", "time" : ISODate("2011-11-03T14:44:15.246Z"), "what" : "moveChunk.commit", "ns" : "test.yql", "details" : { "min" : { "_id" : ObjectId("4eb2a65340643e5bb600e084") }, "max" : { "_id" : { $maxKey : 1 } }, "from" : "shard0002", "to" : "shard0001" } }
{ "_id" : "rac3-2011-11-03T14:44:15-4", "server" : "rac3", "clientAddr" : "10.250.7.220:11131", "time" : ISODate("2011-11-03T14:44:15.389Z"), "what" : "moveChunk.from", "ns" : "test.yql", "details" : { "min" : { "_id" : ObjectId("4eb2a65340643e5bb600e084") }, "max" : { "_id" : { $maxKey : 1 } }, "step1" : 0, "step2" : 204, "step3" : 100023, "step4" : 5007, "step5" : 111, "step6" : 0 } }
mongos> 
相关实践学习
MongoDB数据库入门
MongoDB数据库入门实验。
快速掌握 MongoDB 数据库
本课程主要讲解MongoDB数据库的基本知识,包括MongoDB数据库的安装、配置、服务的启动、数据的CRUD操作函数使用、MongoDB索引的使用(唯一索引、地理索引、过期索引、全文索引等)、MapReduce操作实现、用户管理、Java对MongoDB的操作支持(基于2.x驱动与3.x驱动的完全讲解)。 通过学习此课程,读者将具备MongoDB数据库的开发能力,并且能够使用MongoDB进行项目开发。   相关的阿里云产品:云数据库 MongoDB版 云数据库MongoDB版支持ReplicaSet和Sharding两种部署架构,具备安全审计,时间点备份等多项企业能力。在互联网、物联网、游戏、金融等领域被广泛采用。 云数据库MongoDB版(ApsaraDB for MongoDB)完全兼容MongoDB协议,基于飞天分布式系统和高可靠存储引擎,提供多节点高可用架构、弹性扩容、容灾、备份回滚、性能优化等解决方案。 产品详情: https://www.aliyun.com/product/mongodb
目录
相关文章
|
2月前
|
存储 NoSQL MongoDB
MongoDB基础
MongoDB基础
56 0
|
5月前
|
存储 NoSQL 关系型数据库
【MongoDB系列笔记】MongoDB相关概念
MongoDB 是一个开源、高性能、无模式的文档型数据库,常用于处理高并发、海量数据的场景,尤其适合社交、游戏、物流、物联网和视频直播等领域。与传统的关系型数据库相比,MongoDB 更适合存储结构较为灵活、数据量大且事务性要求不高的数据。当面临高读写需求、大规模数据存储和高可扩展性需求时,可以选择 MongoDB。MongoDB 支持类似于 JSON 的 BSON 数据格式,具有丰富的数据模型,如文档、集合和数据库,以及强大的查询和索引功能。此外,MongoDB 提供复制集以实现高可用性和水平扩展性,以适应业务发展和数据增长。
159 0
|
5月前
|
NoSQL 数据挖掘 BI
【MongoDB】MongoDB 聚合框架
【4月更文挑战第3天】【MongoDB】MongoDB 聚合框架
|
5月前
|
存储 运维 负载均衡
MongoDB详解(二)——MongoDB架构与原理
MongoDB详解(二)——MongoDB架构与原理
155 2
|
5月前
|
存储 NoSQL MongoDB
day03—MongoDB基础
day03—MongoDB基础
89 0
|
NoSQL Linux MongoDB
开发中MongoDB遇到的各种问题
开发中MongoDB遇到的各种问题
158 0
|
存储 SQL NoSQL
mongoDB-基础
不能言而无信 今天就先把这个MongoDB 补了
209 0
mongoDB-基础