mongodb 无法使用配置文件启动 mongod
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25210090/
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
Can't start mongod with config file
提问by haipham23
I installed mongodb on windows 8.1
我在 Windows 8.1 上安装了 mongodb
then I use command promp to navigate to D:\mongodb\bin
然后我使用命令提示符导航到 D:\mongodb\bin
then I use this command
然后我使用这个命令
mongod.exe --config D:\mongodb\mongodb.conf
The content of mongodb.conf
mongodb.conf 的内容
bind_ip = 127.0.0.1,100.100.100.100
port = 3979
quiet = true
dbpath = D:\mongodb\data\db
logpath = D:\mongodb\data\log\mongodb.log
logappend = true
journal = true
But mongod doesn't start. If I use mongod.exe (without using config file), it works perfectly
但是 mongod 没有启动。如果我使用 mongod.exe(不使用配置文件),它可以完美运行
UPDATE:
更新:
My intention is simple: change default port to another port and only allow access from certain IP addresses.
我的意图很简单:将默认端口更改为另一个端口,并且只允许来自某些 IP 地址的访问。
I was using the configuration for Ubuntu. Thanks to Panda_Claus that pointed out the new configuration.
我正在使用 Ubuntu 的配置。感谢 Panda_Claus 指出了新的配置。
So I changed the configuration to
所以我将配置更改为
net:
bindIp: 127.0.0.1,100.100.100.100
port: 3979
The problem is, when I start mongod with this configuration, it got error then automatically exits
问题是,当我用这个配置启动 mongod 时,它出错然后自动退出
ERROR: listen(): bind() failed errno:10049 The requested address is not valid in its context. for socket: 100.100.100.100:3979
So how do I allow only localhost and a specific IP address (in this case is 100.100.100.100) to connect to mongodb?
那么如何只允许 localhost 和特定的 IP 地址(在本例中为 100.100.100.100)连接到 mongodb?
UPDATE 2
更新 2
I used the configuration from maerics
我使用了 maerics 的配置
net:
bindIp: 127.0.0.1,192.168.10.104
port: 3979
storage:
dbPath: D:\mongodb\data\db
journal:
enabled: true
systemLog:
destination: file
path: D:\mongodb\data\log\mongodb.log
quiet: true
logAppend: true
Interestingly, using this, I can only connect to db on local machine, other LAN computer can't connect to
有趣的是,使用这个,我只能连接到本地机器上的数据库,其他局域网计算机无法连接
192.168.10.104:3979.
However, if I remove the
但是,如果我删除
systemLog:
destination: file
path: D:\mongodb\data\log\mongodb.log
quiet: true
logAppend: true
other computers in LAN network are able connect to the database.
LAN 网络中的其他计算机可以连接到数据库。
回答by maerics
The config file must be valid YAML.
配置文件必须是有效的 YAML。
Try modifying the sample file provided with the documentation, for example:
尝试修改随文档提供的示例文件,例如:
net:
bindIp: 127.0.0.1
port: 3979
storage:
dbPath: D:\mongodb\data\db
journal:
enabled: true
systemLog:
destination: file
path: D:\mongodb\data\log\mongodb.log
quiet: true
logAppend: true
回答by Panda_Claus
Not a mongo expert, but it appears from the mongo documentation that you should be using ":" as separators instead of "=".
不是 mongo 专家,但从 mongo 文档看来,您应该使用“:”作为分隔符而不是“=”。
Here's a link I found to support this:
这是我找到的一个链接来支持这一点:
[1]: [http://docs.mongodb.org/manual/reference/configuration-options/"Mongo config file format"][1]
[1]:[ http://docs.mongodb.org/manual/reference/configuration-options/“Mongo配置文件格式”][1]