2团
Published on 2024-08-16 / 6 Visits
0
0

MongoDB新老配置文件转换

1. 旧配置文件

MongoDB原配置文件,类似如下形式:

## 配置文件内容 
pidfilepath = /data/mongodb/shard1/log/shard1.pid 
dbpath = /data/mongodb/shard1/data 
logpath = /data/mongodb/shard1/log/shard1.log 
logappend = true 
bind_ip = 0.0.0.0 
port = 27001
fork = true 
#declare this is a config db of a cluster; 
shardsvr = true 
#副本集名称 
replSet= shard1
#设置最大连接数 
maxConns= 20000 
keyFile= /opt/mongodb/mongo.key

此配置文件比较传统,不太适合添加新配置或进行完善。

2. 配置文件转换

MongoDB自3.X(具体未知)版本开始支持yml格式配置文件,对上述文件进行改造,结果如下所示:

systemLog:
   destination: file
   path: "/data/mongodb/shard1/log/shard1.log" 
   logAppend: true
   logRotate: rename
processManagement:
   fork: true
   pidFilePath: "/data/mongodb/shard1/log/shard1.pid"
net:
   bindIp: 0.0.0.0
   port: 27001
   maxIncomingConnections: 20000
setParameter:
   enableLocalhostAuthBypass: true
storage:
   dbPath: "/data/mongodb/shard1/data"
   wiredTiger:
      engineConfig:
         cacheSizeGB: 4
         journalCompressor: snappy
      collectionConfig:
         blockCompressor: snappy
      indexConfig:
         prefixCompression: true
sharding:
   clusterRole: shardsvr
replication:
   replSetName: shard1
security:
  keyFile: "/opt/mongodb/mongo.key"

需要注意enableLocalhostAuthBypass参数,此参数原配置文件中不包含,其表示从MongoDB宿主机上登录MongoDB执行操作,是否需要进行鉴权,此处为了便利,我设置为不需要进行鉴权。

3.参数转换参考文档

image-yxod.png

Configuration File Settings and Command-Line Options Mapping(需要注意选择对应的MongoDB版本)


Comment