mongod啓動的時候一般會指定一個 configuration file,配置文件中包含的配置等同於命令行options,配置文件格式使用YAML,YAML使用空格縮進。

1:systemLog

verbosity 用於指定日誌級別,默認是0,注意關鍵註釋:

The default log message verbosity level for components . The verbosity level determines the amount of Informational and Debug messages MongoDB outputs

不同的component可以指定不同級別的level,比如systemLog.component.accessControl.verbosity用於指定ACCESS components的日誌級別。

traceAllExceptions比較重要,對於調試和跟蹤問題很有用。

syslogFacility,如果將日誌發送到syslog,則選項對應於syslog的facility level,注意:

To use this option, you must set systemLog.destination to syslog.

path用於將日誌發送到指定的文件,而不是發送到syslog。

logAppend,默認是false,這樣重新啓動mongod的時候會重新創建新文件,如果是true則追加信息到原有文件中。

logRotate可以指定爲rename或reopen,如果logAppend爲true,則該選項必須爲reopen。

destination可以指定爲file和syslog,如果是file,則path選項必須指定。

2:processManagement

fork控制mongod在後臺運行,pidFilePath指定PID文件,一般和fork選項結合使用。

3:net

mongod端口一般是27017,分片端口默認是27018,config server端口默認是27019。

bindIp用於綁定ip地址,如果想全部啓用ipv4地址,指定爲0.0.0.0。

maxIncomingConnections用於控制併發連接數。

wireObjectCheck如果設置爲true,則mongod會拒絕不合法的BSON數據到mongod中。

compression控制不同mongod實例中數據傳輸的壓縮方式。

4:setParameter

Set MongoDB parameter or parameters described in MongoDB Server Parameters

5:storage

dbPath用於指定mongod數據目錄。

indexBuildRetry選項決定是否在重新啓動的時候重建索引:

To stop mongod from rebuilding indexes, set this option to false.

注意該選項和replication.replSetName選項是衝突的。

journal.enabled選項很重要,默認是true,對於mongod崩潰恢復很重要:

Enable or disable the durability journal to ensure data files remain valid and recoverable.Starting in MongoDB 4.0, you cannot specify —nojournal option or storage.journal.enabled: false for replica set members that use the WiredTiger storage engine.

journal.enabled不適用於in-memory存儲引擎。

journal.commitIntervalMs選項控制多久持久化日誌落盤,如果在write操作的時候顯示指定 j:true ,會忽略該參數,立刻落盤。

directoryPerDB選項如果爲true,則每個數據庫會有單獨的目錄。

syncPeriodSecs選項用於控制fsync數據文件的時間,注意:

Do not set this value on production systems. In almost every situation, you should use the default setting.If you set storage.syncPeriodSecs to 0, MongoDB will not sync the memory mapped files to disk.

思考fsync和journal的區別:

The mongod process writes data very quickly to the journal and lazily to the data files. storage.syncPeriodSecs has no effect on the journal files or journaling, but if storage.syncPeriodSecs is set to 0 the journal will eventually consume all available disk space. If you set storage.syncPeriodSecs to 0 for testing purposes, you should also set —nojournal to true.

engine選項很重要,默認是wiredTiger存儲引擎。

6:選項wiredTiger

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

cacheSizeGB表示 internal cache大小,注意和索引內存(maxIndexBuildMemoryUsageMegabytes),文件系統緩存不是一回事。

cacheSizeGB默認最小256M,最大等於50% of (RAM - 1 GB)。

該選項limits the size of the WiredTiger internal cache. The operating system will use the available free memory for filesystem cache, which allows the compressed MongoDB data files to stay in memory. In addition, the operating system will use any free RAM to buffer file system blocks and file system cache.

7:replication

oplogSizeMB用於控制oplog大小,默認大小是可用磁盤空間的5%。需要注意的是mongod啓動後,再設置該參數也不會改變oplog大小,爲了生效,可以使用管理命令 replSetResizeOplog。

replSetName用於指定副本集名稱,在副本集中的所有主機必須有相同的名稱。

參考:

  • https://docs.mongodb.com/manual/reference/configuration-options/
  • https://docs.mongodb.com/manual/reference/log-messages/#log-messages-configure-verbosity
  • https://docs.mongodb.com/manual/reference/parameters/
相關文章