gpt4 book ai didi

mongodb - 如何使用非默认 dbpath 将 mongo db 作为服务运行?

转载 作者:IT老高 更新时间:2023-10-28 13:19:39 26 4
gpt4 key购买 nike

当我尝试启动服务时,我得到了

~$ sudo service mongodb start
mongodb start/running, process 20221

但它并没有真正开始 ~$ sudo 服务 mongodb 状态 mongodb 停止/等待

这可能是因为我的 dbpath 不是默认的那么如何使用非默认 dbpath 启动 m 服务

最佳答案

这实际上与“服务”没有任何关系,它取决于 mongod(MongoDB 的进程名称)参数使用 dbpath 而不是 /data/db

要找出您可以使用的参数,您可以简单地运行...

$ mongod --help

你会得到一个有用的参数列表,还有大量的文档解释了你在启动mongod时可以使用的各种不同的参数......

http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo

http://www.mongodb.org/display/DOCS/Command+Line+Parameters

关于您的问题的文档有点...

Starting mongod

Default Data Directory, Default Port To start Mongo in default mode, where data will be stored in the /data/db directory (or c:\data\db on Windows), and listening on port 27017, just type

$ ./mongod

Alternate Data Directory, Default Port

To specify a directory for Mongo to store files, use the --dbpath option:

$ ./mongod --dbpath /var/lib/mongodb/

Note that you must create the directory and set its permissions appropriately ahead of time -- Mongo will not create the directory if it doesn't exist.

Alternate Port

You can specify a different port for Mongo to listen on for connections from clients using the --port option

$ ./mongod --port 12345

This is useful if you want to run more than one instance of Mongo on a machine (e.g., for running a master-slave pair).

Running as a Daemon

Note: these options are only available in MongoDB version 1.1 and later.

This will fork the Mongo server and redirect its output to a logfile. As with --dbpath, you must create the log path yourself, Mongo will not create parent directories for you.

$ ./mongod --fork --logpath /var/log/mongodb.log --logappend

关于mongodb - 如何使用非默认 dbpath 将 mongo db 作为服务运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10805782/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com