官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/

systemLog

systemLog官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#security-options

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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>

# COMMENT additional component verbosity settings omitted for brevity
参数 类型 默认值 作用
verbosity int 0 默认的日志信息 冗长级别的组件。详细级别确定MongoDB输出的信息和调试消息的数量。
详细程度可以05
0是MongoDB的默认日志详细级别,包括 信息性消息。
1到5增加详细级别,以包括 调试消息。
日志详细级别
建议:使用默认值就可以了
quiet boolean 运行mongos或``mongod`处于安静模式,试图限制输出量。
不建议用于生产系统,因为它可以使在特定的连接变得更加困难跟踪问题
traceAllExceptions boolean 打印详细信息以进行调试。用于支持相关故障排除的其他日志记录。
syslogFacility string user 将mongodb使用日志记录到系统日志中,如果要使用这个选项,必须设置systemLog.destinationsyslog
path string 日志文件的路径,而不是标准输出或主机的syslog
logAppend boolean false mongodmongos重启时,如果为true,将日志追加到原来日志文件内容末尾;如果为false,将创建一个新的日志文件
logRotate string rename 可选项renamereopen
1. rename :重命名日志文件。
2. reopen:按照典型的Linux / Unix日志轮换行为关闭并重新打开日志文件,以避免日志的损失,这个选项必须设置systemLog.logAppendtrue
destination string MongoDB发送所有日志输出的目标。指定 filesyslog。如果指定file,则还必须指定systemLog.path
建议:使用file
timeStampFormat string iso8601-local 日志消息中时间戳的时间格式。
1. ctime:将时间戳显示为: Wed Dec 31 18:17:54.811
2. iso8601-utc:格式显示:1970-01-01T00:00:00.000Z
3. iso8601-local:格式显示:1969-12-31T19:00:00.000-0500
component.accessControl.verbosity int 0 与访问控制相关的组件的日志消息详细级别
建议:使用默认值
component.command.verbosity int 0 与命令相关的组件的日志消息详细级别
建议:使用默认值

processManagement

processManagement文档地址: https://docs.mongodb.com/manual/reference/configuration-options/#processmanagement-options

1
2
3
4
processManagement:
fork: <boolean>
pidFilePath: <string>
timeZoneInfo: <string>
参数 类型 默认值 作用
fork boolean false 是否启用在后台运行mongos或mongod处理的守护程序模式
pidFilePath string 指定一个文件位置来保存的进程ID将mongos或mongod将写入其PID
timeZoneInfo string 加载时区数据库的完整路径。如果未提供此选项,则MongoDB将使用其内置时区数据库

cloud

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#cloud-options

1
2
3
4
5
cloud:
monitoring:
free:
state: <string>
tags: <string>
参数 类型 默认值 作用
free.state string runtime runtime:可以在运行时启用或禁用监控
on:启动监控
off:禁用监控
free.tags string 用于描述环境上下文的可选标记

net

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#net-options

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
net:
port: <int>
bindIp: <string>
bindIpAll: <boolean>
maxIncomingConnections: <int>
wireObjectCheck: <boolean>
ipv6: <boolean>
unixDomainSocket:
enabled: <boolean>
pathPrefix: <string>
filePermissions: <int>
ssl:
sslOnNormalPorts: <boolean> # deprecated since 2.6
certificateSelector: <string>
clusterCertificateSelector: <string>
mode: <string>
PEMKeyFile: <string>
PEMKeyPassword: <string>
clusterFile: <string>
clusterPassword: <string>
CAFile: <string>
clusterCAFile: <string>
CRLFile: <string>
allowConnectionsWithoutCertificates: <boolean>
allowInvalidCertificates: <boolean>
allowInvalidHostnames: <boolean>
disabledProtocols: <string>
FIPSMode: <boolean>
compression:
compressors: <string>
serviceExecutor: <string>
参数 类型 默认值 作用
port int 27017 设置mongodb的访问端口
bindIp string 127.0.0.1 设置mongodb服务器监听ip地址,默认是127.0.0.1;如果监听多个ip地址,使用逗号隔开
bindIpAll boolean false 是否允许所有ip访问数据库
maxIncomingConnections int 65536 最大并发链接数
wireObjectCheck boolean True 是否在收到客户端时验证所有请求,以防止客户端将格式错误或无效的BSON插入MongoDB数据库
ipv6 boolean false 开启或关闭支持ipv6地址
unixDomainSocket.enabled boolean true 启用或禁用UNIX域套接字上的侦听
unixDomainSocket.pathPrefix string /tmp UNIX套接字的路径
unixDomainSocket.filePermissions int 0700 设置UNIX域套接字文件的权限
ssl.sslOnNormalPorts boolean 不推荐使用,为mongos或启用或禁用TLS / SSL
ssl.certificateSelector string 指定证书属性
1.subject:ASCII字符串
2.thumbprint:十六进制字符
ssl.clusterCertificateSelector string 指定证书属性
1.subject:ASCII字符串
2.thumbprint:十六进制字符
ssl.mode string 启用或禁用用于所有网络连接的TLS / SSL或混合TLS / SSL
1.disabled: 服务器不使用TLS / SSL。
2.allowSSL:服务器之间的连接不使用TLS / SSL。对于传入连接,服务器接受TLS / SSL和非TLS /非SSL。
3.preferSSL:服务器之间的连接使用TLS / SSL。对于传入连接,服务器接受TLS / SSL和非TLS /非SSL。
4.requireSSL:服务器仅使用和接受TLS / SSL加密连接。
ssl.PEMKeyFile string 可以使用操作系统安全存储中的证书而不是PEM密钥文件
ssl.PEMKeyPassword string 用于解密证书密钥文件的密码(PEMKeyFile)
ssl.clusterFile string 使用操作系统安全存储中的证书而不是PEM密钥文件
ssl.clusterPassword string 用于解密指定的x.509证书密钥文件的密码(clusterFile)
ssl.CAFile string .pem包含证书颁发机构的根证书链的文件。
.pem使用相对路径或绝对路径指定文件的文件名
ssl.clusterCAFile string .pem包含证书颁发机构的根证书链的文件.
用于验证由建立连接的客户端提供的证书。
.pem使用相对路径或绝对路径指定文件的文件名。
ssl.CRLFile string .pem包含证书吊销列表的文件。
.pem使用相对路径或绝对路径指定文件的文件名
ssl.allowConnectionsWithoutCertificates boolean 建立连接时是否绕过TLS / SSL证书验证
ssl.allowInvalidCertificates boolean 启用或禁用群集中其他服务器上的TLS / SSL证书的验证检查,并允许使用无效证书进行连接
ssl.allowInvalidHostnames boolean false 启用或禁用TLS / SSL证书的主机名的验证
ssl.disabledProtocols string 接受使用特定协议的传入连接。要指定多个协议,请使用逗号分隔的协议列表
TLS1_0`,`TLS1_1`, `TLS1_2
ssl.FIPSMode boolean 启用或禁用使用TLS / SSL库的FIPS模式
``compression.compressors` string snappy 实例之间通信的数据压缩器
1. snappy
2. zilb
serviceExecutor string synchronous synchronous:使用同步网络和管理上的每个连接其网络的线程池
adaptive:使用异步网络和管理上的每个连接其网络的线程池
  • 注意点:PEMKeyFile和clusterFile只能选择一个

security

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#security-options

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
36
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>
clientCertificateSelector: <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>

security.keyFile

  • 类型:string

  • 作用:密钥文件的路径,用于存储MongoDB实例用于在分片集群或副本集中相互进行身份验证的共享密钥

security.clusterAuthMode

  • 类型:string

  • 作用:用于群集身份验证的身份验证模式

  • 作用
    keyFile 使用密钥文件进行身份验证。只接受密钥文件。
    sendKeyFile 发送密钥文件进行身份验证,但可以接受密钥文件和x.509证书。
    sendX509 发送x.509证书进行身份验证,但可以接受密钥文件和x.509证书。
    x509 (推荐) 发送x.509证书以进行身份验证,并仅接受x.509证书
  • 如果使用x.509身份验证,–sslCAFile或ssl.CAFile 必须指定,除非使用–sslCertificateSelector

security.authorization

  • 类型:string

  • 默认值:disabled

  • 作用:启用或禁用基于角色的访问控制(RBAC)以管理每个用户对数据库资源和操作的访问

  • 作用
    enabled 用户只能访问已被授予权限的数据库资源和操作。
    disabled 用户可以访问任何数据库并执行任何操作。

setParameter

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#setparameter-option

1
2
3
setParameter:
<parameter1>: <value1>
<parameter2>: <value2>

查看参数列表

storage

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#storage-options

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
storage:
dbPath: <string>
indexBuildRetry: <boolean>
repairPath: <string>
journal:
enabled: <boolean>
commitIntervalMs: <num>
directoryPerDB: <boolean>
syncPeriodSecs: <int>
engine: <string>
wiredTiger:
engineConfig:
cacheSizeGB: <number>
journalCompressor: <string>
directoryForIndexes: <boolean>
collectionConfig:
blockCompressor: <string>
indexConfig:
prefixCompression: <boolean>
inMemory:
engineConfig:
inMemorySizeGB: <number>
参数 类型 默认值 作用
dbPath string /data/db 设置数据存储文件目录
indexBuildRetry boolean true 开启或关闭是否在mongod下次启动重建不完整的索引
在in-memory存储引擎下不可用
repairPath string dbpath下的A _tmp_repairDatabase_<num>文件目录 为进行恢复操作指定目录

注意:仅仅在MMAPv1存储引擎下可用
journal.enabled boolean true(64-bit系统);false(32-bit系统) 开启和关闭journal,为了保证数据文件的有效性和可恢复性;在设置了dbpath之后有效
在in-memory存储引擎下不可用
journal.commitIntervalMs int 100或30 在MMAPv1上,如果日志与数据文件位于不同的块设备(例如,物理卷,RAID设备或LVM卷)上,则默认日志提交间隔为30毫秒
在WiredTiger上,默认日志提交间隔为100毫秒。
directoryPerDB boolean false mongodb是否为每个数据库建立一个单独的路径,这个路径是在dbpath下创建的
engine string wiredTiger 数据存储引擎
1.wiredTiger
2.inMemory:内存存储引擎
3.mmapv1:不推荐使用
wiredTiger.engineConfig.cacheSizeGB float WiredTiger将用于所有数据的内部缓存的最大大小
使用默认值就行
wiredTiger.engineConfig.journalCompressor string snappy 用于压缩WiredTiger日志数据的压缩类型
wiredTiger.collectionConfig.blockCompressor string snappy 用于压缩集合数据的压缩类型
wiredTiger.indexConfig.prefixCompression boolean true 启用或禁用索引数据的前缀压缩。
inmemory.engineConfig.inMemorySizeGB float 物理内存的50%-1GB 设置缓冲区大小

operationProfiling

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#operationprofiling-options

1
2
3
4
operationProfiling:
mode: <string>
slowOpThresholdMs: <int>
slowOpSampleRate: <double>
参数 类型 默认值 作用
mode string off
slowOpThresholdMs int 100 设置区分慢查询的一个阈值,比如100,当查询速度大于100ms,记录到日志中
slowOpSampleRate double 1.0 应分析或记录的慢速操作部分

replication

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#replication-options

1
2
3
4
5
replication:
oplogSizeMB: <int>
replSetName: <string>
secondaryIndexPrefetch: <string>
enableMajorityReadConcern: <boolean>
参数 类型 默认值 作用
oplogSizeMB int 设置复制日志文件的大小;
replSetName string 副本集的名称。副本集中的所有主机必须具有相同的副本集名称
secondaryIndexPrefetch string all
enableMajorityReadConcern boolean true

sharding

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#sharding-options

1
2
3
sharding:
clusterRole: <string>
archiveMovedChunks: <boolean>
参数 类型 默认值 作用
clusterRole string 设置分片集群中的角色
1.configsvr:作为配置服务器,默认端口27019
2.shardsvr:作为一个分片,默认端口27018
archiveMovedChunks boolean false 在块迁移期间,分片是否保存从分片迁移的文档

auditLog

官方文档地址:https://docs.mongodb.com/manual/reference/configuration-options/#auditlog-options

1
2
3
4
5
auditLog:
destination: <string>
format: <string>
path: <string>
filter: <string>
参数 类型 默认值 作用
destination string 审计日志位置
syslog:JSON文件格式输出在系统日志中,window系统中不可用
console:JSON格式输出
file:输出到文件
format format 设置设计日志输出格式;可用值:JSON/BSON
path path 设计日志输出文件路径
filter filter 审计日志过滤器