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











你可能感兴趣的:(mongodb)