【Mongodb】Mongodb sharding 管理之一

本文涉及的产品
云数据库 MongoDB,通用型 2核4GB
简介: 前面介绍了sharding的基本搭建和大量插入数据测试,本文介绍一些sharding相关查询操作1 判断是否是shard 集群mongos> db.runCommand({ isdbgrid : 1});{ "isdbgrid" : 1, "hostname" : "rac4", "ok" : 1 }mongos> db.
前面介绍了sharding的基本搭建和大量插入数据测试,本文介绍一些sharding相关查询操作
1 判断是否是shard 集群
mongos> db.runCommand({ isdbgrid : 1});
{ "isdbgrid" : 1, "hostname" : "rac4", "ok" : 1 }
mongos> db.runCommand({ismaster:1});
{
        "ismaster" : true,
        "msg" : "isdbgrid",
        "maxBsonObjectSize" : 16777216,
        "ok" : 1
2 查看已经存在的shard集群:必须在admin数据库上
mongos> db.runCommand({ listShards : 1});
{ "ok" : 0, "errmsg" : "access denied - use admin db" }
mongos> use admin
switched to db admin
mongos> db.runCommand({ listShards : 1});
{
        "shards" : [
                {
                        "_id" : "shard0000",
                        "host" : "10.250.7.225:27018"
                },
                {
                        "_id" : "shard0001",
                        "host" : "10.250.7.249:27019"
                },
                {
                        "_id" : "shard0002",
                        "host" : "10.250.7.241:27020"
                }
        ],
        "ok" : 1
}
3 查看一个数据库是否进行了shard
mongos> config = db.getSisterDB("config")
config
mongos> config.system.namespaces.find()
{ "name" : "config.version" }
{ "name" : "config.system.indexes" }
{ "name" : "config.version.$_id_" }
{ "name" : "config.settings" }
{ "name" : "config.settings.$_id_" }
{ "name" : "config.chunks" }
{ "name" : "config.chunks.$_id_" }
{ "name" : "config.chunks.$ns_1_min_1" }
{ "name" : "config.chunks.$ns_1_shard_1_min_1" }
{ "name" : "config.chunks.$ns_1_lastmod_1" }
{ "name" : "config.shards" }
{ "name" : "config.shards.$_id_" }
{ "name" : "config.shards.$host_1" }
{ "name" : "config.mongos" }
{ "name" : "config.mongos.$_id_" }
{ "name" : "config.lockpings" }
{ "name" : "config.lockpings.$_id_" }
{ "name" : "config.locks" }
{ "name" : "config.locks.$_id_" }
{ "name" : "config.lockpings.$ping_1" }
has more
mongos> it
{ "name" : "config.databases" }
{ "name" : "config.databases.$_id_" }
{ "name" : "config.collections" }
{ "name" : "config.collections.$_id_" }
{ "name" : "config.changelog", "options" : { "create" : "changelog", "size" : NumberLong(10485760), "capped" : true } }
查看test数据库,进行了拆分
mongos> test = db.getSisterDB("test")
test
mongos> test.system.namespaces.find()
{ "name" : "test.system.indexes" }
{ "name" : "test.yql" }
{ "name" : "test.yql.$_id_" }
mongos数据库没有进行拆分
mongos> mongos = db.getSisterDB("mongos")
mongos
mongos> mongos.system.namespaces.find()

4 查看整个mongodb 数据库shard的详细信息 
db.printShardingStatus();
 这个命令已经不陌生了,对于此命令的输出:
mongos> printShardingStatus();
--- Sharding Status --- 
第一部分:
  sharding version: { "_id" : 1, "version" : 3 }
第二部分:
  shards:
        {  "_id" : "shard0000",  "host" : "10.250.7.225:27018" }
        {  "_id" : "shard0001",  "host" : "10.250.7.249:27019" }
        {  "_id" : "shard0002",  "host" : "10.250.7.241:27020" }
 介绍了整个sharding 集群的名称,和分布的服务器的ip和端口号。
第三部分:
所有在这个集群上的数据库。
_id 数据库的名字
partitioned 表示是否进行shard 值为true或false,数据库admin没有进行shard,在config服务器上
primary:表示基片,test库有三个shard:shard0000,shard0001,shard0002,其基片为shard0000 表示test数据库在shard000
test.yql chunks:表示collection的分片信息,分为几个区间,哪一个区间在哪一个shard上面。
  databases:
        {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }
        {  "_id" : "mongos",  "partitioned" : false,  "primary" : "shard0000" }
        {  "_id" : "test",   "partitioned" : true,   "primary" : "shard0000" }
                test.yql chunks:
                                shard0000       2
                                shard0002       1
                                shard0001       1
                        { "_id" : { $minKey : 1 } } -->> { "_id" : ObjectId("4eb298b3adbd9673afee95e3") } on : shard0000 { "t" : 2000, "i" : 1 }
                        { "_id" : ObjectId("4eb298b3adbd9673afee95e3") } -->> { "_id" : ObjectId("4eb2a64640643e5bb60072f7") } on : shard0000 { "t" : 1000, "i" : 3 }
                        { "_id" : ObjectId("4eb2a64640643e5bb60072f7") } -->> { "_id" : ObjectId("4eb2a65340643e5bb600e084") } on : shard0002 { "t" : 3000, "i" : 1 }
                        { "_id" : ObjectId("4eb2a65340643e5bb600e084") } -->> { "_id" : { $maxKey : 1 } } on : shard0001 { "t" : 3000, "i" : 0 }
        
相关实践学习
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
目录
相关文章
|
17天前
|
存储 NoSQL MongoDB
【MongoDB】如何在MongoDB中设计Schema?
【4月更文挑战第2天】【MongoDB】如何在MongoDB中设计Schema?
|
2月前
|
存储 缓存 NoSQL
MongoDB详解(三)——MongoDB集群
MongoDB详解(三)——MongoDB集群
35 4
|
7月前
|
NoSQL MongoDB
mongodb
mongodb
25 0
|
8月前
|
NoSQL 前端开发 MongoDB
MongoDB应用
初始化路由模板 数据库和前端页面交互 编写注册的后台接口 先连接数据库 和前台进行数据交互 文章的后台接口 先查询所有的文章内容 发文章 一些验证方法 邮箱验证 用户名随机生成
39 0
|
8月前
|
存储 NoSQL 关系型数据库
什么时候选择MongoDB
什么时候选择MongoDB
65 2
|
9月前
|
JSON NoSQL MongoDB
初学mongoDB(一)
初学mongoDB
47 0
|
9月前
|
存储 NoSQL MongoDB
【mongo 系列】mongodb 学习十,MongoDB 分片集群
之前说到了主从集群,关于主从集群的搭建以及细节后面会再次分享,这次我们先初步来看看 分片集群
114 0
|
12月前
|
SQL JSON NoSQL
老去的MongoDB,未来在哪里?
老去的MongoDB,未来在哪里?
138 0