【Mongodb】 Mongodb sharding 管理之二

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介:
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
相关文章
|
JSON NoSQL MongoDB
Rockmongo详解:高效管理MongoDB的图形化利器
Rockmongo详解:高效管理MongoDB的图形化利器
220 0
|
存储 JSON NoSQL
MongoDB 插入文档:轻松管理数据录入与批量导入
MongoDB 插入文档:轻松管理数据录入与批量导入
208 0
|
存储 NoSQL 大数据
MongoDB 在内容管理场景的应用
MongoDB 在内容管理场景的应用
282 0
|
存储 NoSQL 分布式数据库
MongoDB性能系列最佳实践-Sharding
MongoDB将会推出一系列介绍MongoDB性能最佳实践的文章,旨在帮助用户在多个关键方面实现规模化性能优化。
MongoDB性能系列最佳实践-Sharding
|
缓存 NoSQL Java
Spring Session MongoDB管理会话
Spring Session MongoDB管理会话
163 0
|
NoSQL MongoDB 数据库
mongodb用户权限管理
用户权限管理简要说明
872 0
|
NoSQL MongoDB 数据库
分布式服务器框架之Server.Core库中实现YFUniqueEntity、YFUniqueIDBase 管理MongoDB 自定义Id的自增
YFUniqueEntity是数据库中的结构,GetUniqueID函数中会根据Type和自增步长去数据库中寻找该类型的当前ID是多少,然后会用当前的Id去加上步长,把更新后的新ID插入到MongoDB中记录着ID的那张表里。
|
SQL NoSQL MongoDB
分布式服务器框架之Servers.Core库中实现MongoDB对象实体类 管理对象ID
MongoDB中的ID是一个hash码,和传统的关系数据库相比MongoDB没有办法实现ID的自增,如果需要ID自增的话,所以要自己管理ID,并且把对应类型的ID写入到一个专门的Collection(其实就是Sql中的Table)里面去,每次创建新对象的时候,都要取到该类型当前的ID,然后在这个基础上+1,比如当前是角色的ID是1,又创建了一个新的角色,要在原来的基础上+1 ID=2。今天先把MongoDB的对象实体基类实现了。
|
NoSQL MongoDB 数据库
MongoDB 用户角色管理
MongoDB 服务默认是没有账号密码的,客户端连接上即可进行各种操作。如果在配置文件中,指定了auth=true,即开启了认证,那么客户端连接后需要认证才能执行操作。
MongoDB 用户角色管理
|
存储 JSON NoSQL
4.0版本以上mongodb在Windows下载安装-添加Windows服务-安装可视化工具管理数据教程
4.0版本以上mongodb在Windows下载安装-添加Windows服务-安装可视化工具管理数据教程
311 0
4.0版本以上mongodb在Windows下载安装-添加Windows服务-安装可视化工具管理数据教程

推荐镜像

更多