如何指定 mongodb 的配置文件?

phi*_*012 6 mongodb

我在 ubuntu 服务器上将 mongodb 作为服务运行。如何指定 mongoDB 使用的配置文件?

是否有带有启动命令的文件mongod,我可以编辑该文件以添加--config标志?

Ada*_*m C 9

您说您正在将 MongoDB 作为服务运行,因此我将假设您按照此处说明安装服务,并且您正在使用 Upstart:sudo service mongodb startsudo service mongodb stop.

如果是这种情况,那么控制您的服务的 Upstart 作业将在此处:

/etc/init/mongodb.conf
Run Code Online (Sandbox Code Playgroud)

让我们看一下内容(注意:您将需要 root 权限才能编辑文件):

# Ubuntu upstart file at /etc/init/mongodb.conf

limit nofile 20000 20000

kill timeout 300 # wait 300s between SIGTERM and SIGKILL.

pre-start script
    mkdir -p /var/lib/mongodb/
    mkdir -p /var/log/mongodb/
end script

start on runlevel [2345]
stop on runlevel [06]

script
  ENABLE_MONGODB="yes"
  if [ -f /etc/default/mongodb ]; then . /etc/default/mongodb; fi
  if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb --exec  /usr/bin/mongod -- --config /etc/mongodb.conf; fi
end script
Run Code Online (Sandbox Code Playgroud)

与您的问题有关的部分是从底部算起的第二行。那就是指定要使用的配置文件的那个。这里只是相关的片段:

/usr/bin/mongod -- --config /etc/mongodb.conf
Run Code Online (Sandbox Code Playgroud)

如您所见,配置文件已被指定,因此您需要做的就是对 MongoDB 服务进行配置更改,在/etc/mongodb.conf.

更改配置后,您将需要重新启动服务:sudo service mongodb restart.