为什么 Mongo 不读取 /usr/local/mongodb/mongod.conf 文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7417164/
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
Why doesn't Mongo read the /usr/local/mongodb/mongod.conf file?
提问by Shamoon
In my /usr/local/mongodb/mongod.conf
file, I have
在我的/usr/local/mongodb/mongod.conf
文件中,我有
# Store data alongside MongoDB instead of the default, /data/db/
dbpath = /usr/local/mongodb_data
# Only accept local connections
bind_ip = 127.0.0.1
But when I try to run Mongo (on my mac), I get an error:
但是当我尝试运行 Mongo(在我的 Mac 上)时,出现错误:
Wed Sep 14 09:29:35 [initandlisten] exception in initAndListen std::exception: dbpath (/data/db/) does not exist, terminating
So apparently the conf file is not being read
所以显然 conf 文件没有被读取
采纳答案by Petrogad
You must specify if you want it to use another config; there isn't a default config file.
您必须指定是否希望它使用其他配置;没有默认配置文件。
See Here: File Based Configuration
请参阅此处: 基于文件的配置
To achieve what you want to do; you can either specify your config path or start your mongo server like:
实现你想做的事;您可以指定您的配置路径或启动您的 mongo 服务器,如:
mongod --dbpath /usr/local/mongodb_data
回答by davidmc24
If you install MongoDB using brew, the LaunchAgent files that it generates for you will use a configuration file at /usr/local/etc/mongod.conf by default.
如果您使用brew安装 MongoDB ,默认情况下,它为您生成的 LaunchAgent 文件将使用 /usr/local/etc/mongod.conf 中的配置文件。
This behavior is defined in:
此行为定义在:
https://github.com/Homebrew/homebrew/blob/master/Library/Formula/mongodb.rb
https://github.com/Homebrew/homebrew/blob/master/Library/Formula/mongodb.rb
Note that this "default" only applies when running MongoDB as a service via launchctl
, not manually starting it by running mongodb
.
请注意,此“默认值”仅适用于通过 将 MongoDB 作为服务运行时launchctl
,而不是通过运行mongodb
.
As of 2015-03-09, the instructions given by Homebrew after installing MongoDB 3.0.0 are:
截至2015-03-09,安装MongoDB 3.0.0后Homebrew给出的说明是:
==> Caveats
To reload mongodb after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod --config /usr/local/etc/mongod.conf
Note the explicit --config
argument in the manual run command.
请注意--config
手动运行命令中的显式参数。
回答by Duke
I wanted to just be able to type mongod
and have it work decently. This works, but with caveats:
我只想能够打字mongod
并让它正常工作。这有效,但有警告:
% sudo mkdir /data
% sudo ln -s /usr/local/var/mongodb /data/db
Note that there are some useful configurations in homebrew's default /usr/local/etc/mongod.conf. Here's the file for reference:
请注意,自制软件的默认 /usr/local/etc/mongod.conf 中有一些有用的配置。这是供参考的文件:
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
So it'll log to the console, and connections won't be restricted to localhost.
所以它会登录到控制台,并且连接不会被限制在本地主机上。
Note: as in @ballPointPenguin's post, now that Homebrew has brew services
, that is an excellent option.
注意:就像@ballPointPenguin 的帖子一样,现在 Homebrew 有brew services
,这是一个很好的选择。
回答by ballPointPenguin
As noted by @davidmc24, homebrew installation of mongo will use the configuration file by default when started with launchctl. Simply use:
正如@davidmc24 所指出的,mongo 的 homebrew 安装将在使用 launchctl 启动时默认使用配置文件。只需使用:
brew services start mongodb
You can follow the logs at (default location):
您可以在(默认位置)查看日志:
tail -f /usr/local/var/log/mongodb/mongo.log