mongo配置文件详解

10.142.166.95
10.142.164.235
10.142.164.238
mongod -f /etc/mongodb.conf
tailf /data/mongodb1/mongodb.log
tailf /data/mongodb2/mongodb.log
tailf /data/mongodb3/mongodb.log

sudo ansible -i ansible_hosts ceshi -m shell -a 'df -h'
 sudo ansible -i ansible_hosts ceshi -m shell -a 'cat /etc/mongodb.conf'

mongodb3.x版本后就是要yaml语法格式的配置文件
只能使用空格,不支持tab键,切记,原因你懂的。。。。。。
报错了

[initandlisten] exception in initAndListen: 28574 Cannot start server. Detected data files in /data/mongodb1 created by storage engine 'mmapv1'. The configured storage engine is 'wiredTiger'., terminating
这是该engine  mmapv1
key的权限也要改
chmod 600   /data/mongodb1/keyfile

原版
###########
systemLog:
   destination: file
   path: "/data/mongodb1/mongodb.log"
   logAppend: true
processManagement:
   fork: true
   pidFilePath: /run/mongo.pid
net:
    port: 27017
security:
   keyFile: /data/mongodb1/keyfile 
   authorization: enabled
storage:
   journal:
      enabled: true
   dbPath: /data/mongodb1
   engine: mmapv1 
   wiredTiger:
      engineConfig:
         cacheSizeGB: 10
replication:
   oplogSizeMB: 51200
   replSetName: foo
############
systemLog:
   destination: file
   path: "/data/mongodb2/mongodb.log"
   logAppend: true
processManagement:
   fork: true
   pidFilePath: /run/mongo.pid
net:
    port: 27018
security:
   keyFile: /data/mongodb2/keyfile 
   authorization: enabled
storage:
   journal:
      enabled: true
   dbPath: /data/mongodb2
   engine: mmapv1 
   wiredTiger:
      engineConfig:
         cacheSizeGB: 10
replication:
   oplogSizeMB: 51200
   replSetName: foo

############
systemLog:
   destination: file
   path: "/data/mongodb3/mongodb.log"
   logAppend: true
processManagement:
   fork: true
   pidFilePath: /run/mongo.pid
net:
    port: 27019
security:
   keyFile: /data/mongodb3/keyfile 
   authorization: enabled
storage:
   journal:
      enabled: true
   dbPath: /data/mongodb3
   engine: mmapv1 
   wiredTiger:
      engineConfig:
         cacheSizeGB: 10
replication:
   oplogSizeMB: 51200
   replSetName: foo
##########

/data/mongodb3/keyfile 
9ff6ee24a568dff6b7e1cf7b4aef1aad1c20b82c39d7a6f5f3

注释
systemLog:
   destination: file //指定是一个文件
   path: "/data/mongodb1/mongodb.log" //日志存放位置
   logAppend: true //产生日志内容追加到文件
#  quiet: true//在quite模式下会限制输出信息
#  timeStampFormat: iso8601-utc //默认是iso8601-local,日志信息中还有其他时间戳格式:ctime,iso8601-utc,iso8601-local
processManagement:
   fork: true  //以守护进程的方式运行MongoDB,创建服务器进程
   pidFilePath:/run/mongo.pid  //pid文件路径
net:
   port: 27017 
   bindIp: 0.0.0.0  //绑定ip地址访问mongodb,多个ip逗号分隔
#   maxIncomingConnections: 3000  //默认65535,mongodb实例接受的最多连接数,如果高于操作系统接受的最大线程数,设置无效。
#   http:
#      enabled: true true//http端口最好关闭
#     RESTInterfaceEnabled: true
security:
   keyFile: /data/slot0/bigdata_bigdataops1_mongo/etc/keyfile //指定分片集或副本集成员之间身份验证的key文件存储位置
   authorization: enabled //访问数据库和进行操作的用户角色认证
  clusterAuthMode: "keyFile"//集群认证模式,默认是keyFile

storage:
   journal:
      enabled: true
   dbPath:/data/mongodb1 //数据文件存放路径
   #directoryPerDB: true
   #syncPeriodSecs: 2
   engine: wiredTiger //数据引擎
   wiredTiger:
      engineConfig: //wt引擎配置
         cacheSizeGB: 10 //看服务器情况来进行设置
     directoryForIndexes: true//索引是否按数据库名进行单独存储
      blockCompressor: zlib//压缩配置
    indexConfig:
      prefixCompression: true//索引配置

复制集相关配置,根据以上配置文件进行如下配置。
replication:
   oplogSizeMB: 51200 //默认为磁盘的5%,指定oplog的最大尺寸。对于已经建立过oplog.rs的数据库,指定无效
   replSetName: foo //指定副本集的名称
  secondaryIndexPrefetch: "all"//指定副本集成员在接受oplog之前是否加载索引到内存。默认会加载所有的索引到内存。none不加载;all加载所有;_id_only仅加载_id

分片集群配置,分片复制集配置(单实例节点的基础上)
replication: 
  oplogSizeMB:50
  replSetName: "rs_zxl"
sharding:
  clusterRole: shardsvr

mongos配置,(与单实例不同)
systemLog:
  destination: file
  path: /data/logs/mongos.log
  logAppend: true
net:
  port: 27019
sharding:
  configDB: 192.168.33.131:30000











  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个MongoDB的配置文件示例,其中包含了常用的配置项: ``` # MongoDB配置 # 主机 mongo.host=127.0.0.1 # 端口 mongo.port=27017 # 数据库名 mongo.database=mydb # 用户名 mongo.username= # 密码 mongo.password= # 连接池最小连接数 mongo.minConnectionsPerHost=10 # 连接池最大连接数 mongo.maxConnectionsPerHost=100 # 连接池最大等待队列长度 mongo.maxWaitTime=10000 # 连接超时时间 mongo.connectTimeout=10000 # 等待超时时间 mongo.waitTimeout=120000 # Socket超时时间 mongo.socketTimeout=0 # 是否启用自动重连 mongo.autoConnectRetry=true # 每个主机允许的最大连接数 mongo.connectionsPerHost=100 # 是否启用SSL mongo.sslEnabled=false ``` 上述配置中,`mongo.host`和`mongo.port`分别指定了MongoDB服务器的主机名和端口号,`mongo.database`指定了要连接的数据库名,`mongo.username`和`mongo.password`分别指定了连接数据库的用户名和密码。`mongo.minConnectionsPerHost`和`mongo.maxConnectionsPerHost`分别指定了连接池中的最小和最大连接数,`mongo.maxWaitTime`指定了连接池中等待连接的最大时间,`mongo.connectTimeout`和`mongo.waitTimeout`分别指定了连接和等待超时时间,`mongo.socketTimeout`指定了Socket超时时间。`mongo.autoConnectRetry`指定了是否启用自动重连,`mongo.connectionsPerHost`指定每个主机允许的最大连接数,`mongo.sslEnabled`指定是否启用SSL。 需要注意的是,这只是一个示例配置文件,具体的配置项和值需要根据实际需求进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值