mongod.conf文件

 # mongod.conf
 # for documentation of all options, see:
 # http://docs.mongodb.org/manual/reference/configuration-options/
 # Where and how to store data.
   storage:
   dbPath: /var/lib/mongodb
   journal:
   enabled: true
 #  engine:
 #  mmapv1:
 #  wiredTiger:
 # where to write logging data.
   systemLog:
   destination: file
   logAppend: true
   path: /var/log/mongodb/mongod.log
 # network interfaces
   net:
   port: 27017
   bindIp: 127.0.0.1
 #processManagement:
 #security:
 #operationProfiling:
 #replication:
 #sharding:
 ## Enterprise-Only Options
 #auditLog:
 #snmp:

这是我的mongoDB配置文件,我需要像这样更新文件中的密钥,
port: 27017
bindIp: 0.0.0.0
#security:
keyFile:/opt/mongodb/keyfile
authorization: enabled
#replication:
replSetName: mongoreplica1

如何使用bash脚本执行此操作?

最佳答案

您可以使用

sed -i 's/^\( *bindIp *: *\).*/\10.0.0.0/'

BRE POSIX模式匹配
sed-字符串开始
^\( *bindIp *: *\).*-捕捉组1(参考RHS中的^):零个或多个空格,\( *bindIp *: *\),零个或多个空格,\1和零个或多个空格
bindIp-其他线路

关于linux - 使用sed修改配置文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52271511/

10-09 20:56