Mongodb配置文件详解

Mongodb配置文件YAML格式

可以自定义为mongod.conf或者按照业务名称自定义

systemLog:
  destination: file   #Mongodb 日志输出的目的地,指定一个 file 或者 syslog,如果指定 file,必须指定 systemlog.path
  logAppend: true  #当实例重启时,不创建新的日志文件,在老的日志文件末尾继续添加
  path: /data/mongod/logs/mongod.log    #日志路径
storage:
  dbPath: /data/mongod/data    #数据存储目录
  journal:       #回滚日志
    enabled: true
  directoryPerDB: true    #默认 false,不适用 inmemory engine
 engine:        #存储引擎3.2默认wiredTiger
 mmapv1: #4.0开始启用 mmapv1存储引擎
    preallocDataFiles: <boolean> #启用或禁用数据文件的预分配。默认情况下,MongoDB不会预分配数据文件。
    nsSize: <int>                #默认16M命名空间文件的默认大小,即文件的结尾.ns。每个集合和索引都将计算为一个命名空间。
    quota:
        enforced: <boolean>      #默认 false,启用或禁用每个数据库可以拥有的数字数据文件的最大限制
        maxFilesPerDB: <int>     #默认8,每个数据库的数据文件数量的限制和enforced参数结合使用。。
    smallFiles: <boolean>        #默认 false 选项减少数据文件的初始大小,使用大量的库存较小的文件
  wiredTiger:
     engineConfig:
        cacheSizeGB: 2   #将用于所有数据缓存的最大小
        journalCompressor: <string> #默认snappy,WiredTiger日志数据的压缩类型。
        directoryForIndexes: true #默认false 索引集合storage.dbPath存储在数据单独子目录
     collectionConfig:
        blockCompressor: <string> #默认snappy,用于压缩收集数据的默认压缩类型
     indexConfig:
        prefixCompression: <boolean>  #默认 true启用或禁用索引数据的前缀压缩
  inMemory:
     engineConfig:
        inMemorySizeGB: <number>    #默认值:物理RAM的50%少于1 GB
processManagement:    #使用处理系统守护进程的控制处理
  fork: true  # fork and run in background  后台运行
  pidFilePath: /data/mongod/pid/mongod.pid  # location of pidfile 创建 pid 文件
net:
  port: 28017            #监听端口
  bindIp:  localhost,192.168.0.1     #绑定内网 ip,
  maxIncomingConnections: 5000  #mongos 或者 mongod 最大连接数,如果高于系统配置的最大连接阈值则不起作用
  #http:
    #enabled: true    #开启 http 接口确保生产环境中的REST API和JSON API都被禁用以防止潜在的数据暴露和***者的漏洞。
security:     #认证
  keyFile: /data/mongod/conf/keyfile  #秘钥文件的路径,用于 mongodb 分片集群或者副本集进行身份验证的共享秘钥
  clusterAuthMode: keyFile #集群的认证方式 keyFile 秘钥文件进行身份认证,推荐 x509证书认证
  authorization: enabled  #启用或者禁用基于角色的访问控制来管理每个用户对数据库资源和操作的访问 enabled 或者 disables
  javascriptEnabled:  <boolean> #启用或者禁用服务端JavaScript 执行,禁用时不能使用JavaScript代码的服务端执行操作
  sasl:
     hostName: <string>
     serviceName: <string>
     saslauthdSocketPath: <string>
  enableEncryption: <boolean>  #启用WiredTiger存储引擎的加密。您必须设置为true传递加密密钥和配置
  encryptionCipherMode: <string> #加密的模式适用于企业版
  encryptionKeyFile: <string> #通过KMIP 以外的进程管理密钥时的本地密钥文件的路径只有通过KMIP以外的进程管理密钥时才设置,需要saecurity.enableEncryption是true。
  kmip:
     keyIdentifier: <string>
     rotateMasterKey: <boolean>
     serverName: <string>
     port: <string>
     clientCertificateFile: <string>
     clientCertificatePassword: <string>
     serverCAFile: <string>

replication:   #副本集用到的配置
   oplogSizeMB: 1024 #复制操作日志的大小,详细介绍见oplog文章,
   replSetName: eqxtest3  #副本集名称,同一个副本集的所有主机必须设置相同的名称
   secondaryIndexPrefetch: <string> #只用于 mmapv1存储引擎,默认二进制文件和相关操作索引加载到内存,none 不会加载,all 二次加载,_id_only出了已存在_id,不会加载其他索引
   enableMajorityReadConcern: <boolean> #默认 false

sharding:  #分片用到的配置
   clusterRole: shardsvr  #分片集群角色,configsvr作为配置服务启动,shardsvr 分片实例启动
   archiveMovedChunks: <boolean>  #块迁移期间,一个分片不保存文档从分片迁移,默认 false
   autoSplit: <boolean> # 默认 true,启用或者禁用自动分片,
   configDB: <string> #mongos 分片集群实例必须制定相同的配置服务副本集名字,configDB: <configReplSetName>/cfg1.example.net:27017, cfg2.example.net:27017
   chunkSize: <int> #默认64M

从MongoDB 3.6开始,默认情况下mongod和mongos绑定到localhost。如果部署的成员在不同的主机上运行,​​或者希望远程客户端连接到部署,则必须指定--bind_ip或net.bindIp

猜你喜欢

转载自blog.51cto.com/jiachen/2485891