Convert Command-Line Options to YAML将命令行选项转换为YAML
Starting in MongoDB 4.2, 从MongoDB 4.2开始,mongod and mongos accept --outputConfig command-line option to output the configuration used by the mongod / mongos instance.mongod和mongos接受--outputConfig命令行选项来输出mongod/mongos实例使用的配置。
You can use this option to convert command-line options to YAML configuration.您可以使用此选项将命令行选项转换为YAML配置。
Examples
Convert mongod Command-Line Options to YAML将mongod命令行选项转换为YAML
mongod Command-Line Options to YAMLConsider the following 考虑以下使用命令行选项的mongod invocation that uses the command-line options:mongod调用:
mongod --shardsvr --replSet myShard --dbpath /var/lib/mongodb --bind_ip localhost,My-Example-Hostname --fork --logpath /var/log/mongodb/mongod.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file
Include the 包括--outputConfig command-line option to generate the corresponding YAML file.--outputConfig命令行选项以生成相应的YAML文件。
mongod --shardsvr --replSet myShard --dbpath /var/lib/mongodb --bind_ip localhost,My-Example-Hostname --fork --logpath /var/log/mongodb/mongod.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file --outputConfig
The mongod outputs the following YAML to stdout and exits:mongod将以下YAML输出到stdout并退出:
net:
bindIp: localhost,My-Example-Hostname
tls:
CAFile: /path/to/my/CA/file
certificateKeyFile: /path/to/my/certificate/file
clusterFile: /path/to/my/cluster/membership/file
mode: requireTLS
outputConfig: true
processManagement:
fork: true
replication:
replSet: myShard
security:
clusterAuthMode: x509
sharding:
clusterRole: shardsvr
storage:
dbPath: /var/lib/mongodb
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
To create a configuration file, copy the generated content into a file and delete the 要创建配置文件,请将生成的内容复制到一个文件中,并从YAML中删除outputConfig setting from the YAML.outputConfig设置。
Convert mongos Command-Line Options to YAML将mongos命令行选项转换为YAML
mongos Command-Line Options to YAMLConsider the following 考虑以下使用命令行选项的mongos invocation that uses the command-line options:mongos调用:
mongos --configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath /var/log/mongodb/mongos.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file
Include the 包括--outputConfig command-line option to generate the corresponding YAML for the mongos instance:--outputConfig命令行选项,为mongos实例生成相应的YAML:
mongos --configdb myCSRS/cfg1.example.net:27019,cfg2.example.net:27019 --bind_ip localhost,My-Example-MONGOS-Hostname --fork --logpath /var/log/mongodb/mongos.log --clusterAuthMode x509 --tlsMode requireTLS --tlsCAFile /path/to/my/CA/file --tlsCertificateKeyFile /path/to/my/certificate/file --tlsClusterFile /path/to/my/cluster/membership/file --outputConfig
The mongos outputs the following YAML to stdout and exits:mongos将以下YAML输出到stdout并退出:
net:
bindIp: localhost,My-Example-MONGOS-Hostname
tls:
CAFile: /path/to/my/CA/file
certificateKeyFile: /path/to/my/certificate/file
clusterFile: /path/to/my/cluster/membership/file
mode: requireTLS
outputConfig: true
processManagement:
fork: true
security:
clusterAuthMode: x509
sharding:
configDB: myCSRS/cfg1.example.net:27019,cfg2.example.net:27019
systemLog:
destination: file
path: /var/log/mongodb/mongos.log
To create a configuration file, copy the generated content into a file and delete the 要创建配置文件,请将生成的内容复制到一个文件中,并从YAML中删除outputConfig setting from the YAML.outputConfig设置。