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
命令
sed -i 's/^\( *bindIp *: *\).*/\10.0.0.0/'
BRE POSIX 模式 ^\( *bindIp *: *\).*
匹配
^
- 字符串的开始\( *bindIp *: *\)
- 捕获第 1 组(用 RHS 中的\1
表示):零个或多个空格,bindIp
,零个或多个空格,:
和零个或多个空格.*
- 行的其余部分
关于linux - 使用sed修改配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52271511/