一 配置文件说明
MongoDB有两种配置文件格式,分别是:
3.2版官方yaml配置文件选项参考
- 用
=
号的常规格式
类似my.conf等常规配置的文件
- yaml语法的新格式
mongodb3.x版本后就是要yaml语法格式的配置文件,下面是yaml配置文件格式如下:
切记yaml只能使用空格,不支持tab键,切记
配置举例
配置文件
1 2 3 4 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
|
指定配置启动
1 2 3
| mongod --config /etc/mongod.conf
mongod -f /etc/mongod.conf
|
配置文件模块
mongod.conf配置文件分为如下几块内容:
1 2 3 4 5 6 7 8 9 10 11
| systemLog: storage: processManagement: net: security: operationProfiling: replication: sharding: setParameter: auditLog: snmp:
|
二 详细配置部分
A systemLog日志相关参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| systemLog: verbosity: <int> quiet: <bool> traceAllExceptions: <bool> syslogFacility: <string> path: <string> logAppend: <bool> logRotate: rename|reopen destination: <string> timeStampFormat: <string> component: accessControl: verbosity: <int> command: verbosity: <int>
|
B storage存储引擎相关参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| storage: dbPath: <string> indexBuildRetry: <bool> repairPath: <string> journal: enabled: <boolean> commitIntervalMs: <num> directoryPerDB: <bool> syncPeriodSecs: <int> engine: <string> wiredTiger: engineConfig: cacheSizeGB: <number> journalCompressor: <string> directoryForIndexes: <bool> collectionConfig: blockCompressor: <string> indexConfig: prefixCompression: <bool>
|
C processManagement进程相关参数
1 2 3
| processManagement: fork: <boolean> pidFilePath: <string>
|
D 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
| net: prot: <int> bindIp: <string> maxIncomingConnections: <int> wireObjectCheck: <boolean> ipv6: <bool> http: enabled: <boolean> JSONEnabled: <boolean> RESTInterfaceEnabled: <boolean> ssl: sslOnNormalPorts: <boolean> 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>
|
E 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: authorization: enabled keyFile: /path/mongo.key clusterAuthMode: <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> saslMechanism: <string> queryUser: <string> queryPassword: <string> useOSDefaults: <boolean> transportSecurity: <string> timeoutMS: <int> userToDNMapping: <string> authz: queryTemplate: <string>
|
F operationProfiling慢查询相关参数:
1 2 3 4
| operationProfiling: slowOpThresholdMs: <int> mode: <string>
|
G replication副本集相关参数:
1 2 3 4 5
| replication: oplogSizeMB: <int> replSetName: <string> secondaryIndexPrefetch: <string> enalbeMajorityReadConcern: <boolean>
|
H sharding分片相关参数:
1 2 3
| sharding: clusterRole: <string> archiveMovedChunks: <bool>
|
I setParameter自定义变量:
1 2 3 4
| setParameter: <parameter1>: <value1> <parameter2>: <value2> enableLocalhostAuthBypass: false
|
J auditLog审计相关参数:
1 2 3 4 5
| auditLog: destination: <string> format: <string> path: <string> filter: <string>
|