索引好处:加快索引相关的查询
坏处:增加磁盘空间消耗,降低写入性能

评判当前索引构建情况:
    1. mongostat工具介绍
    2. profile集合介绍
    3. 日志介绍
    4. explain分析

1. mongostat工具

    mongostat:查看MongoDB运行状态程序。
    使用:mongostat -h 127.0.0.1:12345

输出字段说明  --help
 Fields
   inserts     - # of inserts per second (* means replicated op)
   query       - # of queries per second
   update     - # of updates per second
   delete     - # of deletes per second
   getmore     - # of get mores (cursor batch) per second
   command     - # of commands per second, on a slave its local|replicated
   flushes     - # of fsync flushes per second
   mapped     - amount of data mmaped (total data size) megabytes
   vsize       - virtual size of process in megabytes
   res         - resident size of process in megabytes
   non-mapped - amount virtual memeory less mapped memory (only with --all)
   faults     - # of pages faults per sec
   locked     - name of and percent time for most locked database
   idx miss   - percent of btree page misses (sampled)
   qr|qw       - queue lengths for clients waiting (read|write)
   ar|aw       - active clients (read|write)
   netIn       - network traffic in - bytes
   netOut     - network traffic out - bytes
   conn       - number of open connections
   set         - replica set name
   repl       - replication type
                   PRI - primary (master)
                   SEC - secondary
                   REC - recovering
                   UNK - unknown
                   SLV - slave
              b    RTR - mongos process ("router")
详细说明参考(http://www.imooc.com/video/6443
... ... 

使用(两个窗口一个添加,一个监控)
添加:
1
2
3
> use jerome
switched to db jerome
for(i=0;i<100000;i++)db.jerome.insert({x:i})
查看当前系统情况

qr,我们比较关注的,读队列。qw写队列
 如果idx miss,比较高存在隐患,可能要构建索引。
 

2. profile集合

1
2
3
4
5
6
7
8
9
10
11
12
> db.getProfilingStatus()  #查看profile设置
"was" : 0, "slowms" : 100 }
> db.setProfilingLevel(2) #设置级别
"was" : 0, "slowms" : 100, "ok" : 1 }
> db.getProfilingStatus()
"was" : 2, "slowms" : 100 }
> show tables #查看生成的集合
jerome
jerome_2
location
system.indexes
system.profile
was分为三个级别:0 1 2 
0:关闭。
1:配合slowms,记录所有操作超过slowms的操作。
2:记录任何操作

查看(natural自然排序)
1
2
3
4
> db.system.profile.find().sort({$naturl:-1}).limit(3)
"op" "query""ns" "jerome.system.indexes""query" : { "expireAfterSeconds" : { "$exists" true } }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 11, "nscannedObjects" : 11, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(206), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(4), "w" : NumberLong(7) } }, "nreturned" : 0, "responseLength" : 20, "millis" : 0, "execStats" : { "type" "COLLSCAN""works" : 13, "yields" : 0, "unyields" : 0, "invalidates" : 0, "advanced" : 0, "needTime" : 12, "needFetch" : 0, "isEOF" : 1, "docsTested" : 11, "children" : [ ] }, "ts" : ISODate("2015-06-06T09:12:23.021Z"), "client" "0.0.0.0""allUsers" : [ { "user" "__system""db" "local" } ], "user" "__system@local" }
"op" "command""ns" "jerome.$cmd""command" : { "profile" : -1 }, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(0), "w" : NumberLong(21) }, "timeAcquiringMicros" : { "r" : NumberLong(0), "w" : NumberLong(8) } }, "responseLength" : 58, "millis" : 0, "execStats" : {  }, "ts" : ISODate("2015-06-06T09:12:23.051Z"), "client" "127.0.0.1""allUsers" : [ ], "user" "" }
"op" "query""ns" "jerome.system.namespaces""query" : {  }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 16, "nscannedObjects" : 16, "keyUpdates" : 0, "numYield" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(235), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(7), "w" : NumberLong(7) } }, "nreturned" : 16, "responseLength" : 640, "millis" : 0, "execStats" : { "type" "COLLSCAN""works" : 18, "yields" : 0, "unyields" : 0, "invalidates" : 0, "advanced" : 16, "needTime" : 1, "needFetch" : 0, "isEOF" : 1, "docsTested" : 16, "children" : [ ] }, "ts" : ISODate("2015-06-06T09:12:34.167Z"), "client" "127.0.0.1""allUsers" : [ ], "user" "" }
里面参数详细说明(http://www.imooc.com/video/6445

注意:生产环境一般不使用profile,因为会占据性能。

3. 日志

可以配置文件配置日志记录情况,v越多月详细。(mongod.conf)


4.explain分析


通过后面添加.explain(),可以看到查询的详细信息。
查询使用时间112,可以通过建立x索引优化。

mongoDB安全

    1. MongoDB安全概览
    2. 物理隔离与网络隔离
    3. IP白名单隔离
    4.用户名密码鉴权
MongoDB安全概览
    1. 最安全的是物理隔离:不现实
    2. 网络隔离其次
    3. 防火墙再其次
    4. 用户名密码在最后

MongoDB安全
    1. auth开启
    2. keyfile开启    
1. auth开启
在配置文件里面配置

重启MongoDB,查看日志,可以看到

然后创建用户
    1. 创建语法:createUser(2.6之前为addUser)
    2. {user:"<name>",
        pwd:"",
        customData:{<any information>},
        role:[{role:"",db:""}]}
    3. 角色类型:内建类型(read,readWrite,dbAdmin,dbOwner,userAdmin)权限类型也可以自定义
    

    使用
    

    之前指定的数据库是test,所以只能操作test
    

    指定的是只能read,没有write(提示么有权限)
    

MongoDB用户角色详解
    1. 数据库角色(read,readWrite,dbAdmin,dbOwner,userAdmin)
    2. 集群角色(clusterAdmin,clusterManager)
    3. 备份角色(backup,restore...)
    4. 其他特殊权限(DBAdminAnyDatabase)
    除了这些,还有两个,一个是root,有所有的权限。一个是--**,一般这两个内置的role不会对外开放。 

 ... ... 



索引构建情况分析、mongoDB安全(四)的更多相关文章

  1. MongoDB数据库索引构建情况分析

    前面的话 本文将详细介绍MongoDB数据库索引构建情况分析 概述 创建索引可以加快索引相关的查询,但是会增加磁盘空间的消耗,降低写入性能.这时,就需要评判当前索引的构建情况是否合理.有4种方法可以使 ...

  2. MySQL全面瓦解25:构建高性能索引(案例分析篇)

    回顾一下上面几篇索引相关的文章: MySQL全面瓦解22:索引的介绍和原理分析 MySQL全面瓦解23:MySQL索引实现和使用 MySQL全面瓦解24:构建高性能索引(策略篇) 索引的十大原则 1. ...

  3. MongoDB系列四(索引).

    一.索引简介 再来老生常谈一番,什么是索引呢?数据库索引与书籍的索引类似.有了索引就不需要翻整本书,数据库可以直接在索引中查找,在索引中找到条目以后,就可以直接跳转到目标文档的位置,这能使查找速度提高 ...

  4. 根文件系统的构建与分析(四)之瑞士军刀busybox生成系统基本命令

    根文件系统的构建与分析(四) 转载请注明 http://blog.csdn.net/jianchi88   Author:Lotte   邮箱:baihaowen08@126.com ls /bin, ...

  5. SqlServer之like、charindex、patindex 在有无索引的情况下分析

    1.环境介绍 测试环境 SQL2005 测试数据 200W条 2.环境准备 2.1建表 CREATE TABLE [dbo].[Depratments](         [Dep_id] [int] ...

  6. .NET应用架构设计—面向对象分析与设计四色原型模式(彩色建模、领域无关模型)(概念版)

    阅读目录: 1.背景介绍 2.问自己,UML对你来说有意义吗?它帮助过你对系统进行分析.建模吗? 3.一直以来其实我们被一个缝隙隔开了,使我们对OOAD遥不可及 4.四色原型模式填补这个历史缝隙,让我 ...

  7. SQL Server 索引维护(1)——如何获取索引使用情况

    前言: 在前面一文中,已经提到了三类常见的索引问题,那么问题来了,当系统出现这些问题时,该如何应对? 简单而言,需要分析现有系统的行为,然后针对性地对索引进行处理: 对于索引不足的情况:检查缺少索引的 ...

  8. 复旦大学2016--2017学年第二学期高等代数II期末考试情况分析

    一.期末考试成绩班级前十五名 林晨(93).朱民哲(92).何陶然(91).徐钰伦(91).吴嘉诚(91).于鸿宝(91).宁盛臻(90).杨锦文(89).占文韬(88).章俊鑫(87).颜匡萱(87 ...

  9. 《构建之法》第四&十七章读书笔记

     <构建之法>第四&十七章读书笔记 一.         前言 再次阅读<构建之法>,愈发被其中生动有趣的举例吸引.作为一本给予软件工程学生的书籍,其不以枯燥的理论知识 ...

随机推荐

  1. 转:linux/unix命令行终端的光标及字符控制快捷键

    from:http://linux.chinaunix.net/techdoc/system/2007/11/23/973027.shtml 在使用linux/unix的命令行终端时,有时候会碰到键盘 ...

  2. javascript 中如何判断是否是JSON格式的字符串

    var stringToJson = function(value){ try{ eval('('+value+')'); return angular.fromJson(value); } catc ...

  3. eclipse中启动tomcat,localhost:8080无法访问

    问题 eclipse中启动tomcat,项目可以正常运行,但是localhost:8080无法访问. 关闭eclipse中的Tomact,直接从tomcat/bin 下的startup.bat启动,l ...

  4. Windows环境下,从零开始搭建Nodejs+Express+Ejs框架(一)---安装nodejs

    第一步,安装nodejs https://nodejs.org/en/download/ 这个是nodejs的官网,由于操作系统是win7 64位的,所以,我下载的是node-v8.11.1-x64的 ...

  5. GDAL打开mdb文件失败解决方法

    使用GDAL打开mdb文件时提示下面错误信息: ERROR 1: Unable to initialize ODBC connection to DSN for DRIVER=Microsoft Ac ...

  6. Docker: Failed to get D-Bus connection: No connection to service

    Issue: When you execute systemctl command in docker container, you may receive following error. Erro ...

  7. TCP发送源码学习(3)--tcp_transmit_skb

    一.tcp_transmit_skb static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it, g ...

  8. Android中Sqlite数据库进行增删改查

    今天这篇文章写Sqlite数据库,通过一个小案例来完整讲一下数据库常见的CRUD操作. 先对知识点总结: SQLite数据库 轻量级关系型数据库 创建数据库需要使用的api:SQLiteOpenHel ...

  9. Cassandra 3.x官方文档(1)---关于Cassandra

    写在前面 cassandra3.x官方文档的非官方翻译.翻译内容水平全依赖本人英文水平和对cassandra的理解.所以强烈建议阅读英文版cassandra 3.x 官方文档.此文档一半是翻译,一半是 ...

  10. logstash分析日志

    待处理日志格式如下: [totalCount: 298006556, count: 287347623, queryCount: 259027994, exeCount: 28319629, tota ...