What is the correct way to start a mongod service

2019-01-08 03:15发布

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.

I get "Command not found" in response to:

 init mongod start

In response to:

~: service mongod start
service: This command still works, but it is deprecated. Please use launchctl(8) instead.
service: failed to start the 'mongod' service

And if I try:

~: launchctl start mongod
launchctl start error: No such process

So obviously I'm blundering around a bit. Next step seems to be typing in random characters until something works. The command which does work is: mongod --quiet & I'm not sure, maybe that is the way you're supposed to do it? Maybe I should just take off 'quiet mode' and add > /logs/mongo.log to the end of the command line?

I'm building a development environment on a Mac with the intention of doing the same thing on a linux server. I'm just not sure of the Bash commands. All the other searches I do with trying to pull up the answer give me advice for windows machines.

Perhaps someone knows the linux version of the commands?

Thanks very much

10条回答
叼着烟拽天下
2楼-- · 2019-01-08 03:39

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.

查看更多
等我变得足够好
3楼-- · 2019-01-08 03:39

mongod --dbpath [path_to_data_directory]

查看更多
贪生不怕死
4楼-- · 2019-01-08 03:41

First Step

install mongodb in your linux machine with

apt install mongodb-client && apt install mongodb-server

second step is

change the database path instead of your system default path if you want.
so do the following steps and change it for yourself.

mongod --directoryperdb --dbpath /var/lib/mongodb/data/db --logpath /var/lib/mongodb/log/mongodb.log --logappend --rest

and in your windows machine do it just like that just put an --install flag. you have to get a successful message.

Best Regards...

查看更多
Lonely孤独者°
5楼-- · 2019-01-08 03:47

If you feel like having a simple gui to fix this (as I do), then I can recommend the mongodb pref-pane. Description: http://blog.mongodb.org/post/28925264384/macosx-preferences-pane-for-mongodb

On github: https://github.com/remysaissy/mongodb-macosx-prefspane

查看更多
登录 后发表回答