管理mongod进程¶

开启``mongod``进程¶

默认情况下,MongoDB将数据存储在 /data/db 目录里。在Windows里,MongoDB将数据存储在 C:\data\db 里。在所有平台上,MongoDB对来自 27017 端口上的客户端连接进行监听。

On Windows, this path is on the drive from which you start MongoDB. For

example, if you do not specify a --dbpath, starting a MongoDB

server on the C:\ drive stores all data files in C:\data\db.

全部使用默认配置来启动MongoDB,只需要在系统shell里发出以下命令即可:

mongod

指定数据目录¶

If you want mongod to store data files at a path other

than /data/db you can specify a dbPath. The

dbPath must exist before you start mongod. If it

does not exist, create the directory and the permissions so that

mongod can read and write data to this path. For more

information on permissions, see the security operations

documentation.

可以使用 --dbpath 选项,为 mongod 指定一个 dbPath 来当做数据目录使用。下面的调用将会启动一个 mongod 实例并将数据存储在 /srv/mongodb 路径下。

mongod --dbpath /srv/mongodb/

指定TCP端口¶

在只有一个进程的时候,可以在一个网络接口上监听所有连接。如果您在一台服务器上运行多个 mongod 进程,或者有其他一些进程必须使用这个端口,那么您必须分配不同的端口去监听每一个客户端的连接。

为 mongod 指定一个端口,请在命令行使用 --port 选项。下面的命令将启动 mongod 并在``12345``: 端口监听它。

mongod --port 12345

为了避免混淆,请尽可能的使用默认的端口号。

将 mongodb 以守护进程的方式启动¶

要运行一个 mongod 进程来作为一个守护进程(也就是 fork),并且 将输出写入到一个日志文件里,可以使用 --fork 和 --logpath 选项。您必须创建一个log目录;可是,如果这个日志文件不存在的话,mongod 会代劳。

The following command starts mongod as a daemon and records log

output to /var/log/mongodb.log.

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

附加的配置选项¶

For an overview of common configurations and deployments

for common use cases, see

Run-time Database Configuration.