【Mongodb】Mongodb sharding 管理之一

前面介绍了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 }

时间: 2024-07-30 21:47:21

【Mongodb】Mongodb sharding 管理之一的相关文章

【Mongodb】Sharding 集群配置

mongodb的sharding集群由以下3个服务组成: Shards  Server: 每个shard由一个或多个mongod进程组成,用于存储数据 Config  Server: 用于存储集群的Metadata信息,包括每个Shard的信息和chunks信息 Route   Server: 用于提供路由服务,由Client连接,使整个Cluster看起来像单个DB服务器 另外,Chunks是指MongoDB中一段连续的数据块,默认大小是200M,一个Chunk位于其中一台Shard服务器上

ASP.NET MVC4使用MongoDB制作相册管理_实用技巧

ASP.NET MVC4使用MongoDB制作相册管理实例分享 TIPS:1.Image转成Base64保存到mongodb字段          2.数据模型是嵌套的关联  首先定义Model层:  public class Photo : IEquatable<Photo> { [Required] public string PhotoName { get; set; } [Required] public string PhotoDescription { get; set; } pu

【Mongodb】 Mongodb sharding 管理之二

shard 集群的系统信息也是保留在config数据库的集合里面的.本文介绍一些Shard 的配置信息查询, mongos> use config switched to db config 查询当前的版本 mongos> db.getCollection("version").findOne() { "_id" : 1, "version" : 3 } 查询当前的配置chunkSize的大小 mongos> db.settin

MongoDB 生态 - 可视化管理工具

工欲善其事,必先利其器,我们在使用数据库时,通常需要各种工具的支持来提高效率:很多新用户在刚接触 MongoDB 时,遇到的问题是『不知道有哪些现成的工具可以使用』,本系列文章将主要介绍 MongoDB 生态在工具.driver.可视化管理等方面的支持情况. 本文主要介绍 MongoDB 的一些可视化运维管理工具 MongoDB Cloud Manager MongoDB Cloud Manager是官方推出的运维自动化管理系统,是企业版才支持的功能,社区用户也可以下载试用.Cloud Mana

【Mongodb】Sharding 手工迁移chunk

mongodb的数据由monogd服务器存储,由mongos对写入的数据根据片键进行路由,整个过程对客户端完全透明.对chunk的移动是由"平衡器"来决定的,当然加入chunk分布不均匀了,我们也可以手工来操作 db.runCommand( { moveChunk : "" ,                  find : {查询条件} ,                  to : "" } ) 注释: moveChunk:一个集合的全字要加

【Mongodb】sharding 集群Add/Remove 节点

MongoDB的Auto-Sharding能够做到: 1 当各Sharding间负载和数据分布不平衡时,自动rebalancing 2 简单方便的添加和删除节点 3 自动故障转移(auto failover) 4 可扩展至上千台节点  如何增加shard节点,在之前的shard集群配置过程使用过.当向一个sharding集群添加新的节点,mongodb 会将在其他节点的数据chunk迁移到新的节点上面.以便达到均分数据的目的,这也算是负载均衡吧. 添加之前: mongos> db.printSh

深入理解MongoDB分片的管理_MongoDB

前言 在MongoDB(版本 3.2.9)中,分片集群(sharded cluster)是一种水平扩展数据库系统性能的方法,能够将数据集分布式存储在不同的分片(shard)上,每个分片只保存数据集的一部分,MongoDB保证各个分片之间不会有重复的数据,所有分片保存的数据之和就是完整的数据集.分片集群将数据集分布式存储,能够将负载分摊到多个分片上,每个分片只负责读写一部分数据,充分利用了各个shard的系统资源,提高数据库系统的吞吐量. 数据集被拆分成数据块(chunk),每个数据块包含多个do

MongoDB用户权限管理讲解

Mongodb在2.4最新版本中对用户权限管理做了全新的调整,把权限细化了,增强了安全性,越来越像mysql的权限管理了. 一.2.4之前的版本用户管理 1.创建某个数据库的管理用户 1.1.进入weiw数据库: >use weiw; 1.2.添加用户(读写权限,readOnly-->false): >db.addUser("java","java");默认是拥有weiw数据库所有权限 >db.addUser("java1"

MongoDB Web界面 管理工具Rockmongo的安装

RockMongo是PHP5写的一个MongoDB管理工具. 通过 Rockmongo 你可以管理 MongoDB服务,数据库,集合,文档,索引等等. 它提供了非常人性化的操作.类似 phpMyAdmin(PHP开发的MySql管理工具). 安装 PHP WEB环境 安装mongo的php扩展 a)      下载php_mongo.dll 官方下载地址:http://pecl.php.net/package/mongo 下载时看准文件版本,要和你使用php的版本相同 如果版本使用错了mongo