配置文件
MongoDB常用配置参数可以由config配置文件统一设置实现。Mongod的配置文件是mongod…yaml,Mongos的配置文件为mongos.yaml。MongoDB在2.6版本开始,配置文件
采用YAML格式。在使用配置文件前,先需要手工建立YAML配置文件内容,配置文件详细内容可以参考后续网络配置、存储配置内容。
配置文件模块
net: #网络
systemLog: #日志
storage: #存储引擎
processManagement: #进程管理
security: #安全
operationProfiling: #性能分析器
replication: #主从复制
sharding: #分片集群
setParameter: #自定义变量
auditLog: #监测日志
snmp:
网络模块
net:
prot: <int> #监听端口,默认27017
bindIp: <string> #绑定IP,如果此值是“0.0.0.0”则绑定所有接口,允许多ip绑定,用逗号分隔
maxIncomingConnections: <int> #进程允许的最大连接数,上限是系统阈值(ulimit),默认65535
wireObjectCheck: <boolean> #当客户端写入数据时,是否检查数据的有效性(BSON),有效的数据才执行,默认true
ipv6: <bool> #是否支持多实例之间使用ipv6,默认false
http: #http配置 3.2以后弃用,不安全
enabled: <boolean>
JSONEnabled: <boolean>
RESTInterfaceEnabled: <boolean>
ssl: #https配置
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: #数据压缩 3.4支持Snappy压缩器
compressors: <string>
日志模块
systemLog:
verbosity: <int> #日志级别,默认0,1-5均会包含debug信息
quiet: <bool> #安静,true时将会减少日志的输出量
traceAllExceptions: <bool> #打印异常详细信息
syslogFacility: <string> #启用syslog指定用于登录时信息到syslog Facility水平,前提是
path: <string> #日志路径
logAppend: <bool> #追加日志还是新建日志
logRotate: rename|reopen #日志轮询。默认值rename;reopen前提为 logAppend: true
destination: <string> #日志输出目的地,可为file或syslog,不指定会输出到标准输出
timeStampFormat: <string> #日志时间戳格式,有 ctime,Iso869-utc,iso8691-local
component: #为不同的组件指定各自的日志信息级别
accessControl:
verbosity: <int>
command:
verbosity: <int>
存储引擎模块
storage:
dbPath: <string> #数据存储目录 /data/db
indexBuildRetry: <bool> #构件索引时mongod意外关闭,启动是否重建索引,默认true
repairPath: <string> #在repair期间临时数据目录 A_tmp_repairDatabase_<num>
journal: #数据操作记录日志
enabled: <boolean> #journal日志是否持久存储,通常用于数据故障恢复,建议开启 默认64位为true,32位为false
commitIntervalMs: <num> #mongod日志刷新值,范围1-500毫秒,默认100,不建议修改
directoryPerDB: <bool> #是否将不同的数据存储在不同的目录中,需为dbPath子目录,默认false
syncPeriodSecs: <int> #fsync操作将数据flush到磁盘的时间间隔,默认为60秒,不建议修改
engine: <string> #存储引擎类型,3.2前默认 mmapv1,3.2后默认WiredTiger
wiredTiger: #存储引擎配置
engineConfig:
cacheSizeGB: <number> #最大缓存大小256~10TB,3.4版本开始wridTiger默认:50%RAM减去1GB
journalCompressor: <string> #日志压缩算法,可选值有 none,snappy(默认),zlib
directoryForIndexes: <bool> #是否将索引和集合数据分别存储在dbPath单独的目录中,默认false
collectionConfig:
blockCompressor: <string> #collection数据压缩算法,可选none, snappy(默认),zlib
indexConfig:
prefixCompression: <bool> #是否对索引数据使用前缀压缩。可有效减少索引数据的内存使用量。默认true
进程管理模块
processManagement:
fork: <boolean> #是否以守护进程运行,默认false
pidFilePath: <string> #将mongod进程ID写入指定文件,默认不会创建
安全模块
security:
authorization: enabled #MondoDB认证功能,默认disabled
keyFile: /path/mongo.key #MongoDB副本集节点身份验证密钥文件
clusterAuthMode: <string> #集群members间的认证模式
transitionToAuth: <boolean> #过度方式授权,默认false
javascriptEnabled: <boolean> #是否允许执行JavaScript脚本,默认true
redactClientLogData: <boolean> #无业务数据日志记录方式,默认false
sasl: #Sasl协议
hostName: <string> #实现基于Sasl和Kerberos协议支持的服务器域名设置
serviceName: <string> #设置基于Sasl协议的服务器注册名称。仅用于企业版
saslauthdSocketPath: <string> #设置Unix域Socket文件路径
enableEncryption: <boolean> #WiredTiger存储引擎加密,默认false(企业版)
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>
性能分析器(慢查询相关参数)
operationProfiling:
slowOpThresholdMs: <int> #“慢查询”的时间阈值,单位毫秒(默认100ms)
mode: <string> #数据库profiler级别,可选值“off|slowOp|all”
# 数据库profiling会影响性能,建议只在性能调试阶段开启,mongod会把慢查询记录到日志中
replication副本集相关参数
replication:
oplogSizeMB: <int> #replication操作日志的最大尺寸,如果太小则全量同步
replSetName: <string> #副本集名称,副本集中所有的mongod实例都必须有相同的名字
secondaryIndexPrefetch: <string> #副本集中的secondary,从oplog中应用变更操作前,会先把索引加载到内存
enalbeMajorityReadConcern: <boolean> #允许readConcern的级别为“majority”
sharding分片相关参数
sharding:
clusterRole: <string> #在sharding集群中的角色。configsvr(27019)|shardsvr(27018)
archiveMovedChunks: <bool> #当chunks迁移后,是否归档并保存这些chunks在dbPath/movechunk目录下
setParameter自定义变量
setParameter:
<parameter1>: <value1>
<parameter2>: <value2>
enableLocalhostAuthBypass: false #示例
auditLog审计相关参数:
auditLog:
destination: <string> #指定审计记录的输出方式,有syslog|console|file
format: <string> #输出格式,有JSON 和 BSON
path: <string> #如果输入为文件,那么指定文件完整路径及文件名
filter: <string> #过滤器,可限制审计系统记录的操作类型