如何在 mongodb 配置文件中设置授权?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25325142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set authorization in mongodb config file?
提问by mlibre
I run mongod.exe
in server with this option in cmd.exe
:
我mongod.exe
在服务器中运行此选项cmd.exe
:
mongod.exe --dbpath=path --auth
And now, how can I do this in a config file?
my mongod.cfg
:
现在,我怎样才能在配置文件中做到这一点?
我的mongod.cfg
:
dbpath=D:\Program Files\MongoDB 2.6 Standard\data
security=
authorization= enabled
I get this error :
我收到此错误:
Error parsing INI config file: unknown option security.
解析 INI 配置文件时出错:选项安全性未知。
回答by Gary
For mongod version 2.4(ini config file)
对于 mongod 2.4 版(ini 配置文件)
auth = true
https://docs.mongodb.com/v2.4/reference/configuration-options/#auth
https://docs.mongodb.com/v2.4/reference/configuration-options/#auth
For mongod versions 2.6+(yaml config file)
对于 mongod版本 2.6+(yaml 配置文件)
security:
authorization: enabled
https://docs.mongodb.com/v3.2/reference/configuration-options/#security.authorizationhttps://docs.mongodb.com/v3.0/reference/configuration-options/#security.authorizationhttps://docs.mongodb.com/v2.6/reference/configuration-options/#security.authorization
https://docs.mongodb.com/v3.2/reference/configuration-options/#security.authorization https://docs.mongodb.com/v3.0/reference/configuration-options/#security.authorization https: //docs.mongodb.com/v2.6/reference/configuration-options/#security.authorization
回答by keithics
mongodb version 3.2
MongoDB 版本 3.2
this is the correct config
这是正确的配置
security:
authorization: "enabled"
with quotes since the value is a string as per the documentation
带引号,因为根据文档,该值是一个字符串
回答by Robert Walters
security:
authorization: "enabled"
This is correct as stated above, one thing to note is if it still doesn't work make sure you didn't use a tab for the authorization line it won't work you need to just use spaces.
如上所述,这是正确的,要注意的一件事是,如果它仍然不起作用,请确保您没有在授权行中使用选项卡,它不会起作用,您只需要使用空格即可。
回答by Malcolm Murdoch
Just needs to say
只需要说
auth=true
You don't need any of the other options!
您不需要任何其他选项!
回答by Burak Dalk?ran
If you are use YAML
如果您使用 YAML
security:
authorization: "enabled"
working for 2.6 or high.
工作 2.6 或更高。
But if you don't use YAML.
但是如果你不使用 YAML。
auth: true
I'm use mongodb v3.0.2, v3.6.5, v4.0.3, both files are working correctly.
我使用的是 mongodb v3.0.2、v3.6.5、v4.0.3,两个文件都正常工作。
INI CONFIG
配置文件
# mongodb.conf
# Where to store the data.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
bind_ip = 0.0.0.0
port = 27017
journal=true
auth = true
YAML CONFIG
YAML 配置
# 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: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: "enabled"
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
回答by BertC
On DigitalOcean you get the 3.6.3 version but with 2.* style config files. Which makes it confusion when reading all the comments above.
在 DigitalOcean 上,您可以获得 3.6.3 版本,但带有 2.* 样式的配置文件。这使得在阅读上述所有评论时感到困惑。
So, instead of following the DigitalOcean Guide of installing MongoDB (this one), you'd better take the official MongoDB Guide (this one)
因此,与其遵循安装 MongoDB 的 DigitalOcean 指南(此一),不如阅读官方 MongoDB 指南(此一)
回答by user2915814
Really late to they party.
他们聚会真的晚了。
For me nothing of the above worked (on windows, on Linux "authorization: enabled" works fine as long as permissions are right). Ended up creating a service of my own with --dbpath and --auth options using a third party service manager. Works like a charm.
对我来说,上面没有任何工作(在 Windows 上,在 Linux 上,只要权限正确,“授权:启用”就可以正常工作)。最终使用第三方服务管理器使用 --dbpath 和 --auth 选项创建了我自己的服务。奇迹般有效。
I perfectly aware that this is not a direct answer but I hope, this will help someone.
我完全知道这不是一个直接的答案,但我希望这会对某人有所帮助。
Side note though, I could not use "C:\Program Files\MongoDB\4.2\Server\data" folder. No write permissions.
不过,请注意,我无法使用“C:\Program Files\MongoDB\4.2\Server\data”文件夹。没有写权限。
回答by Harkole
For me the key thing that was causing the fault/error was noted in Robert Walters response - Use of the TAB in the config file.
对我来说,导致故障/错误的关键因素在 Robert Walters 的响应中指出 - 在配置文件中使用 TAB。
Changing this to 4 whitespaces fixed the issue whilst keeping the config file looking neat/readable.
将此更改为 4 个空格解决了问题,同时保持配置文件看起来整洁/可读。