mongodb 配置文件

mongodb 配置文件

本文檔是在mongodb爲3.4下編寫的,僅做爲參考,詳細內容請參考:https://docs.mongodb.com/manual/reference/configuration-options/#configuration-filejavascript

一.說明php

     配置mongodb有兩種方式,一種是經過mongod和mongos兩個命令;另一種方式就是配置文件的方式。由於更容易去管理,因此後者更受你們的青睞。html

二. 配置文件格式java

    mongodb 配置文件採用的YAML格式;mysql

    例如:linux

1sql

2mongodb

3數據庫

4express

5

6

7

8

9

10

11

12

13

14

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的簡寫)

          例如:

1

2

3

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

 

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

  或

1

2

3

mongod -f  D:/mongodb/mongod.conf

 

mongos -f  D:/mongodb/mongos.conf

四 配置文件的核心選項

 1. systemLog 選項

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

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 選項    

1

2

3

processManagement:

   fork: <boolean>

   pidFilePath: <string>

  processMangement.fork

             類型:Boolean

             默認值:False

            做用:在前臺啓動Mongodb進程,若是Session窗口關閉,Mongodb進程也隨之中止。不過Mongodb同時還提供了一種後臺Daemon方式啓動,只須要加上一個"--fork"參數便可,值得注意的是,用到了"--fork"參數就必須啓用"--logpath"參數。以下所示:

       

1

2

3

4

5

[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參數也能夠配置配置文件中,以下所示:

1

2

3

4

5

port=27017 

dbpath=data/db 

logpath=log/mongodb.log 

logappend=true 

fork=true 

 net 選項 

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

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 選項     

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

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語言格式

1

2

3

setParameter:

   <parameter1>: <value1>

   <parameter2>: <value2>

  storage 選項

   

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

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系統) ,\data\db(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 選項

1

2

3

4

5

6

7

8

9

10

11

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 選項

1

2

3

4

5

6

7

8

9

10

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 選項

1

2

3

4

storage:

   inMemory:

      engineConfig:

         inMemorySizeGB: <number>

  storage.inmemory.engineConfig.inMemorySizeGB

                     類型:float

                     默認值:物理內存的50%-1GB

                    做用:設置緩衝區大小;

    opeartionProfiling 選項       

1

2

3

operationProfiling:

   slowOpThresholdMs: <int>

   mode: <string>

  opeartionProfiling.slowOpThresholdMs

                類型:integer

                默認值:100

                 做用:設置區分慢查詢的一個閾值,好比100,當查詢速度大於100ms,記錄到日誌中

        operationProfiling.mode

                 類型:string

                 默認值:off

      replication 選項       

1

2

3

4

5

replication:

   oplogSizeMB: <int>

   replSetName: <string>

   secondaryIndexPrefetch: <string>

   enableMajorityReadConcern: <boolean>

  replication.oplogSizeMB

               類型:integer

                做用:設置複製日誌文件的大小;

 sharding 選項   

1

2

3

sharding:

   clusterRole: <string>

   archiveMovedChunks: <boolean>

   sharding.clusterRole

              類型:string

               做用:設置分片集羣中的角色;

值   描述
configsvr 做爲配置服務器,默認端口27019
shardsvr 做爲一個分片,默認端口27018

 auditLog 選項 (MongoDB Enterprise可用)

1

2

3

4

5

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>, ... }

相關文章
相關標籤/搜索