What Is the Correct Way to Start a Mongod Service on Linux/Os X

What is the correct way to start a mongod service on linux / OS X?

With recent builds of mongodb community edition, this is straightforward.

When you install via brew, it tells you what exactly to do. There is no need to create a new launch control file.

$ brew install mongodb
==> Downloading https://homebrew.bintray.com/bottles/mongodb-3.0.6.yosemite.bottle.tar.gz ### 100.0%
==> Pouring mongodb-3.0.6.yosemite.bottle.tar.gz
==> Caveats
To have launchd start mongodb at login:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
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
==> Summary
/usr/local/Cellar/mongodb/3.0.6: 17 files, 159M

Start mongod service at system startup

You can either put the command in your /etc/bashrc script under and if condition i.e. if the mongod process is not already running, then start it.

Other way is to modify your /etc/rc.local and add the command to start mongod in that file. It will start at bootup.

Mongod service won't start in OSX

Create a folder somewhere in your drive and start it using

mongod --dbpath yourfolder --logpath myfile.log --logappend

.. and check the result.

I have several instances of mongo running in my Mac with Maverick OSX and it works perfectly.
I think it's the best way to test it. After that you can review what's going on with the config files.
If this works you can add --fork at the end to fork the process.

Installing and Running MongoDB on OSX

Assuming you have created the data/db directory under bin after install.

  1. Start a terminal for your mongo server
  2. Go to <mongodb-install-directory>/bin directory
  3. Run the command

    ./mongod

  4. Start a terminal for your mongo shell

  5. Go to <mongodb-install-directory>/bin directory
  6. Run the command (make sure you put the name of the database)

    ./mongo test

MongoDB start error

mongo is the client shell, it's not a server. You start a MongoDB server with the mongod command. For example:

mongod --dbpath ~/mongodb/data

You can also start mongod automatically when your OS starts up. You can find instructions here: https://stackoverflow.com/a/17061202/236660

After the server is started, you can use mongo to connect to the server.

Note that you can also run the mongo shell without connecting to any server:

mongo --nodb

Of course, you won't be able to do much with just the shell.



Related Topics



Leave a reply



Submit