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

前端 未结 11 1420
予麋鹿
予麋鹿 2020-11-30 16:39

I\'ve installed mongodb and have been able to run it, work with it, do simple DB read / write type stuff. Now I\'m trying to set up my Mac to run mongod as a service.

相关标签:
11条回答
  • 2020-11-30 16:59

    Homebrew's services tap integrates formulas with the launchctl manager. Adding it is easy:

    brew tap homebrew/services
    

    You can then launch MongoDB with this command (this will also start mongodb on boot):

    brew services start mongodb
    

    You can also use stop or restart:

    brew services stop mongodb
    brew services restart mongodb
    
    0 讨论(0)
  • 2020-11-30 16:59

    I did a bit of looking around on the Mac side. You may want to use the installer here as it looks like it does all the setup for you to automatically launch on Mac OS. The only downside is it looks like it's using a pretty old mongo version.

    This link here also explains the setup to get mongo automatically launching as a background service on the Mac.

    0 讨论(0)
  • 2020-11-30 17:02

    Edit: you should now use brew services start mongodb, as in Gergo's answer...

    When you install/upgrade mongodb, brew will tell you what to do:

    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
    

    It works perfectly.

    0 讨论(0)
  • 2020-11-30 17:04
    mongod --dbpath [path_to_data_directory]
    
    0 讨论(0)
  • 2020-11-30 17:09

    On macOS 10.13.6 with MongoDB 4.0

    I was unable to connect to localhost from the mongo shell

    I started MongoDB with:

    mongod --config /usr/local/etc/mongod.conf

    I found that the 'mongod.conf' had:

    bindIp: 127.0.0.1

    Change my JavaScript connection from localhost to 127.0.0.1 and it worked fine.

    The same was occurring with MongoDB Compass too.

    0 讨论(0)
  • 2020-11-30 17:09

    mongod wasn't working to start the daemon for me but after I ran the following, it started working:

    'mongod --fork --logpath /var/log/mongodb.log'
    

    (from here: https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/)

    0 讨论(0)
提交回复
热议问题