zoukankan      html  css  js  c++  java
  • mongodb 配置文件

    本文档是在mongodb为3.4下编写的,仅作为参考,详细内容请参考:https://docs.mongodb.com/manual/reference/configuration-options/#configuration-file

    一.说明

         配置mongodb有两种方式,一种是通过mongod和mongos两个命令;另外一种方式就是配置文件的方式。因为更容易去管理,所以后者更受大家的青睐。

    二. 配置文件格式

        mongodb 配置文件采用的YAML格式;

        例如:

    systemLog:
       destination: file
       path: "/var/log/mongodb/mongod.log"
       logAppend: true
    storage:
       journal:
          enabled: true
    processManagement:
       fork: true
    net:
       bindIp: 127.0.0.1
       port: 27017
    setParameter:
       enableLocalhostAuthBypass: false
    

    三 使用配置文件

               通过mongod和mongos命令去执行配置文件,这里要使用他们的一个选项--config(这里是两个横线,具体查看 > mongod --help)或者-f(--config的简写)

              例如:

    mongod --config  D:/mongodb/mongod.conf
    
    mongos --config  D:/mongodb/mongos.conf
    

      或

    mongod -f  D:/mongodb/mongod.conf
    
    mongos -f  D:/mongodb/mongos.conf

    四 配置文件的核心选项

     1. systemLog 选项

    systemLog:
       verbosity: <int>  
       quiet: <boolean>
       traceAllExceptions: <boolean>
       syslogFacility: <string>
       path: <string>
       logAppend: <boolean>
       logRotate: <string>
       destination: <string>
       timeStampFormat: <string>
       component:
          accessControl:
             verbosity: <int>
          command:
             verbosity: <int>
    

     systemLog.traceAllExceptions

                   类型:boolean

                   作用: 为调试打印详细信息,用于支持相关的故障排除。

         systemLog.syslogFacility

                   类型:string

                   默认值:user

                   作用:将mongodb使用日志记录到系统日志中,如果要使用这个选项,必须开启--sysylog选项

          systemLog.path

                   类型:string

                   作用:指定日志文件的目录

            syetemLog.logAppend

                   类型:boolean

                    默认值:False

                   作用:当mongod或mongos重启时,如果为true,将日志追加到原来日志文件内容末尾;如果为false,将创建一个新的日志文件

             systemLog.destination

                   类型:string

                   作用:指定日志文件的路径,如果设置了这个值,必须指定systemLog.path.如果没有设置,日志会标准的输出到后台

             systemLog.timeStampFormat

                    类型:string

                    默认值:iso8601-local

                   作用:为日志添加时间戳。

    描述
    ctime  显示时间戳格式为:Wed Dec 31 18:17:54.811.
    iso8601-utc 安装iso-8601-utc格式显示:1970-01-01T00:00:00.000Z
    iso8601-local 按照iso8601-local格式显示:1969-12-31T19:00:00.000-0500

      processMangement 选项    

    processManagement:
       fork: <boolean>
       pidFilePath: <string>
    

      processMangement.fork

                 类型:Boolean

                 默认值:False

                作用:在前台启动Mongodb进程,如果Session窗口关闭,Mongodb进程也随之停止。不过Mongodb同时还提供了一种后台Daemon方式启动,只需要加上一个"--fork"参数即可,值得注意的是,用到了"--fork"参数就必须启用"--logpath"参数。如下所示:

           

    [root@localhost mongodb]# ./bin/mongod --dbpath=data/db --fork  
    --fork has to be used with --logpath  
    [root@localhost mongodb]# ./bin/mongod --dbpath=data/db --fork --logpath=log/mongodb.log   
    all output going to: /opt/mongodb/log/mongodb.log  
    forked process: 3300  
    

      daemon方式启动的fork参数也可以配置配置文件中,如下所示:

    port=27017  
    dbpath=data/db  
    logpath=log/mongodb.log  
    logappend=true  
    fork=true  
    

     net 选项 

    net:
       port: <int>
       bindIp: <string>
       maxIncomingConnections: <int>
       wireObjectCheck: <boolean>
       ipv6: <boolean>
       unixDomainSocket:
          enabled: <boolean>
          pathPrefix: <string>
          filePermissions: <int>
       http:
          enabled: <boolean>
          JSONPEnabled: <boolean>
          RESTInterfaceEnabled: <boolean>
       ssl:
          sslOnNormalPorts: <boolean>  # deprecated since 2.6
          mode: <string>
          PEMKeyFile: <string>
          PEMKeyPassword: <string>
          clusterFile: <string>
          clusterPassword: <string>
          CAFile: <string>
          CRLFile: <string>
          allowConnectionsWithoutCertificates: <boolean>
          allowInvalidCertificates: <boolean>
          allowInvalidHostnames: <boolean>
          disabledProtocols: <string>
          FIPSMode: <boolean>
       compression:
          compressors: <string>
    

      net.port

                    类型:integer

                   默认值:27017

                    作用:设置mongodb的监听TCP端口

           net.bindIp

                    类型:string

                    作用:设置mongodb服务器监听ip地址,默认是127.0.0.1;如果监听多个ip地址,使用逗号隔开

            net.maxIncomingConnections

                    类型:integer 

                   默认值:65536

                   作用:最大并发链接数

           net.ipv6

                  类型:boolean

                  默认值:false

                 作用:开启或关闭支持ipv6地址;

      security 选项     

     

    security:
       keyFile: <string>
       clusterAuthMode: <string>
       authorization: <string>
       transitionToAuth: <boolean>
       javascriptEnabled:  <boolean>
       redactClientLogData: <boolean>
       sasl:
          hostName: <string>
          serviceName: <string>
          saslauthdSocketPath: <string>
       enableEncryption: <boolean>
       encryptionCipherMode: <string>
       encryptionKeyFile: <string>
       kmip:
          keyIdentifier: <string>
          rotateMasterKey: <boolean>
          serverName: <string>
          port: <string>
          clientCertificateFile: <string>
          clientCertificatePassword: <string>
          serverCAFile: <string>
       ldap:
          servers: <string>
          bind:
             method: <string>
             saslMechanisms: <string>
             queryUser: <string>
             queryPassword: <string>
             useOSDefaults: <boolean>
          transportSecurity: <string>
          timeoutMS: <int>
          userToDNMapping: <string>
          authz:
             queryTemplate: <string>
    

      ....查看mongodb手册 #security选项

    setParameter 选项

         设置mongodb参数,查看参数列表

         采用YAML语言格式

    setParameter:
       <parameter1>: <value1>
       <parameter2>: <value2>
    

      storage 选项

       

    storage:
       dbPath: <string>
       indexBuildRetry: <boolean>
       repairPath: <string>
       journal:
          enabled: <boolean>
          commitIntervalMs: <num>
       directoryPerDB: <boolean>
       syncPeriodSecs: <int>
       engine: <string>
       mmapv1:
          preallocDataFiles: <boolean>
          nsSize: <int>
          quota:
             enforced: <boolean>
             maxFilesPerDB: <int>
          smallFiles: <boolean>
          journal:
             debugFlags: <int>
             commitIntervalMs: <num>
       wiredTiger:
          engineConfig:
             cacheSizeGB: <number>
             journalCompressor: <string>
             directoryForIndexes: <boolean>
          collectionConfig:
             blockCompressor: <string>
          indexConfig:
             prefixCompression: <boolean>
       inMemory:
          engineConfig:
             inMemorySizeGB: <number>
    

      storage.dbPath

                    类型:string

                    默认值:/data/db(linux和macOS系统) ,datadb(window系统)

                   作用:设置数据存储文件目录

         storage.indexBuildRetry

                   类型:boolean

                   默认值:true

                   作用:开启或关闭是否在mongod下次启动重建不完整的索引。

                   注:在in-memory存储引擎下不可用

    storage.repairPath

                   类型:string

                   默认值:在dbpath下的A _tmp_repairDatabase_<num> 文件目录

                   作用:为进行恢复操作指定目录

                    注意:仅仅在MMAPv1存储引擎下可用

      storage.journal.enabled

                  类型:boolean

                   默认值:true(64-bit系统);false(32-bit系统)

                   作用:开启和关闭journal,为了保证数据文件的有效性和可恢复性;在设置了dbpath之后有效

                    注:在in-memory存储引擎下不可用

            

       storage.directoryPerDB

           类型:boolean

            默认值:false

             作用:当为true,mongodb为每个数据库建立一个单独的路径,这个路径是在dbpath下创建的;每次创建需要重启服务器

               注:在in-memory存储引擎下不可用

       storage.engine

               默认值:wiredTiger

               作用:这是数据存储引擎

    描述
    MMAPV1 MMAPCV1 storage engine
    wiredTiger WiredTiger Storage Engine.
    inMemory In-Memory Storage Engine.

       storage.mmapv1 选项

    storage:
       mmapv1:
          preallocDataFiles: <boolean>
          nsSize: <int>
          quota:
             enforced: <boolean>
             maxFilesPerDB: <int>
          smallFiles: <boolean>
          journal:
             debugFlags: <int>
             commitIntervalMs: <num>
    

      storage.mmapv1.preallocDataFiles

                     类型:boolean

                     默认值:true

                     作用:开启或关闭数据文件的预分配;

       storage.mmapv1.quota.enforced

                     类型:boolean

                     默认值:false

                      作用:开启或关闭每个数据库中的数据文件个数的限额;默认是每个数据库最多有8个数据文件,通过调整storage.mmapv1.quota.maxFilesPerDB

            storage.mmapv1.quota.maxFilesPerDB

                      类型:integer

                          默认值:8

                          作用:设置每个数据库中数据文件的限制个数;

         storage.wiredTiger 选项

    storage:
       wiredTiger:
          engineConfig:
             cacheSizeGB: <number>
             journalCompressor: <string>
             directoryForIndexes: <boolean>
          collectionConfig:
             blockCompressor: <string>
          indexConfig:
             prefixCompression: <boolean>
    

      storage.wiredTiger.engineConfig.cacheSizeGB

                      类型:float

                      作用:设置缓存大小,从3.4版本开始,内存的50%-1GB 和256MB的最大值

            storage.wriedTiger.engineConfig.journalCompressor

                      默认值:snappy

                      作用:设置journal压缩方式;可选项:none/snappy/zlib

      storage.inmemory 选项

    storage:
       inMemory:
          engineConfig:
             inMemorySizeGB: <number>
    

      storage.inmemory.engineConfig.inMemorySizeGB

                         类型:float

                         默认值:物理内存的50%-1GB

                        作用:设置缓冲区大小;

        opeartionProfiling 选项       

    operationProfiling:
       slowOpThresholdMs: <int>
       mode: <string>
    

      opeartionProfiling.slowOpThresholdMs

                    类型:integer

                    默认值:100

                     作用:设置区分慢查询的一个阈值,比如100,当查询速度大于100ms,记录到日志中

            operationProfiling.mode

                     类型:string

                     默认值:off

          replication 选项       

    replication:
       oplogSizeMB: <int>
       replSetName: <string>
       secondaryIndexPrefetch: <string>
       enableMajorityReadConcern: <boolean>
    

      replication.oplogSizeMB

                   类型:integer

                    作用:设置复制日志文件的大小;

     sharding 选项   

    sharding:
       clusterRole: <string>
       archiveMovedChunks: <boolean>
    

       sharding.clusterRole

                  类型:string

                   作用:设置分片集群中的角色;

    值   描述
    configsvr 作为配置服务器,默认端口27019
    shardsvr 作为一个分片,默认端口27018

     auditLog 选项 (MongoDB Enterprise可用)

    auditLog:
       destination: <string>
       format: <string>
       path: <string>
       filter: <string>
    

      auditLog.destination 

                     类型:string

                     作用:审计日志位置;

    描述
    syslog JSON文件格式输出在系统日志中,window系统中不可用
    console JSON格式输出
    file 输出到文件

        auditLog.format

                  类型:string

                  作用:设置设计日志输出格式;可用值:JSON/BSON

       auditLog.path

                 类型:string

                    作用:设计日志输出文件路径

        auditLog.filter

                 类型:string

                  作用:审计日志过滤器

                  格式:{ <field1>: <expression1>, ... }

     

                  

                  

                  

  • 相关阅读:
    接口测试基础
    python学习笔记(一)
    Charles学习笔记
    接口测试笔记
    【CSS】Beginner5:Margins&Padding
    【CSS】Beginner4:Text
    【CSS】Beginner3:Color
    【CSS】Beginner2:Selectors, Properties, and Values
    【CSS】Beginner1:Applying CSS
    【HTML】Beginner9:Form
  • 原文地址:https://www.cnblogs.com/phpandmysql/p/7763394.html
Copyright © 2011-2022 走看看