开发者

Why doesn't Mongo read the /usr/local/mongodb/mongod.conf file?

In my /usr/local/mongodb/mongod.conf file, I have

# Store data alongside MongoDB instead of the default, /data/db/
dbpath = /usr/local/mongodb_data

# Only accept local connections开发者_JAVA百科
bind_ip = 127.0.0.1

But when I try to run Mongo (on my mac), I get an error:

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


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.

This behavior is defined in:

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.

As of 2015-03-09, the instructions given by Homebrew after installing MongoDB 3.0.0 are:

==> 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.


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:

mongod --dbpath /usr/local/mongodb_data


As noted by @davidmc24, homebrew installation of mongo will use the configuration file by default when started with launchctl. Simply use:

brew services start mongodb

You can follow the logs at (default location):

tail -f /usr/local/var/log/mongodb/mongo.log


I wanted to just be able to type mongod and have it work decently. This works, but with caveats:

% 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:

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜