我应该在哪里为MongoDB添加--rest选项?

我应该在哪里为MongoDB添加--rest选项?,mongodb,Mongodb,我需要将mongodb与--rest选项一起使用。但是mongodb是在引导时自动启动的,所以我想我需要修改一个文件或其他东西 在哪里可以添加这个--rest选项 我的文件位于/etc/init/mongodb.conf,不确定要编辑什么: # Ubuntu upstart file at /etc/init/mongodb.conf limit nofile 20000 20000 kill timeout 300 # wait 300s between SIGTERM and SIGKI

我需要将mongodb与--rest选项一起使用。但是mongodb是在引导时自动启动的,所以我想我需要修改一个文件或其他东西

在哪里可以添加这个--rest选项

我的文件位于/etc/init/mongodb.conf,不确定要编辑什么:

# 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
此文件位于/etc/init.d/mongodb:

#!/bin/sh -e
# upstart-job
#
# Symlink target for initscripts that have been converted to Upstart.

set -e

INITSCRIPT="$(basename "$0")"
JOB="${INITSCRIPT%.sh}"

if [ "$JOB" = "upstart-job" ]; then
    if [ -z "$1" ]; then
        echo "Usage: upstart-job JOB COMMAND" 1>&2
    exit 1
    fi

    JOB="$1"
    INITSCRIPT="$1"
    shift
else
    if [ -z "$1" ]; then
        echo "Usage: $0 COMMAND" 1>&2
    exit 1
    fi
fi

COMMAND="$1"
shift


if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
    ECHO=echo
else
    ECHO=:
fi

$ECHO "Rather than invoking init scripts through /etc/init.d, use the service(8)"
$ECHO "utility, e.g. service $INITSCRIPT $COMMAND"

# Only check if jobs are disabled if the currently _running_ version of
# Upstart (which may be older than the latest _installed_ version)
# supports such a query.
#
# This check is necessary to handle the scenario when upgrading from a
# release without the 'show-config' command (introduced in
# Upstart for Ubuntu version 0.9.7) since without this check, all
# installed packages with associated Upstart jobs would be considered
# disabled.
#
# Once Upstart can maintain state on re-exec, this change can be
# dropped (since the currently running version of Upstart will always
# match the latest installed version).

UPSTART_VERSION_RUNNING=$(initctl version|awk '{print $3}'|tr -d ')')

if dpkg --compare-versions "$UPSTART_VERSION_RUNNING" ge 0.9.7
then
    initctl show-config -e "$JOB"|grep -q '^  start on' || DISABLED=1
fi

case $COMMAND in
status)
    $ECHO
    $ECHO "Since the script you are attempting to invoke has been converted to an"
    $ECHO "Upstart job, you may also use the $COMMAND(8) utility, e.g. $COMMAND $JOB"
    $COMMAND "$JOB"
    ;;
start|stop)
    $ECHO
    $ECHO "Since the script you are attempting to invoke has been converted to an"
    $ECHO "Upstart job, you may also use the $COMMAND(8) utility, e.g. $COMMAND $JOB"
    if status "$JOB" 2>/dev/null | grep -q ' start/'; then
        RUNNING=1
    fi
    if [ -z "$RUNNING" ] && [ "$COMMAND" = "stop" ]; then
        exit 0
    elif [ -n "$RUNNING" ] && [ "$COMMAND" = "start" ]; then
        exit 0
    elif [ -n "$DISABLED" ] && [ "$COMMAND" = "start" ]; then
        exit 0
    fi
    $COMMAND "$JOB"
    ;;
restart)
    $ECHO
    $ECHO "Since the script you are attempting to invoke has been converted to an"
    $ECHO "Upstart job, you may also use the stop(8) and then start(8) utilities,"
    $ECHO "e.g. stop $JOB ; start $JOB. The restart(8) utility is also available."
    if status "$JOB" 2>/dev/null | grep -q ' start/'; then
        RUNNING=1
    fi
    if [ -n "$RUNNING" ] ; then
        stop "$JOB"
    fi
    # If the job is disabled and is not currently running, the job is
    # not restarted. However, if the job is disabled but has been forced into the
    # running state, we *do* stop and restart it since this is expected behaviour
    # for the admin who forced the start.
    if [ -n "$DISABLED" ] && [ -z "$RUNNING" ]; then
        exit 0
    fi
    start "$JOB"
    ;;
reload|force-reload)
    $ECHO
    $ECHO "Since the script you are attempting to invoke has been converted to an"
    $ECHO "Upstart job, you may also use the reload(8) utility, e.g. reload $JOB"
    reload "$JOB"
    ;;
*)
    $ECHO
    $ECHO "The script you are attempting to invoke has been converted to an Upstart" 1>&2
    $ECHO "job, but $COMMAND is not supported for Upstart jobs." 1>&2
    exit 1
esac

通过添加以下行,通过
/etc/mongodb.conf
启用REST接口可能更干净:

rest = true

该设置已记录在案。

MongoDB 2.6版已切换到YAML配置文件。需要以下两个条目来防止以下启动警告:
mongodb警告:--rest未指定--httpinterface

net:
  http:
    enabled: true
    RESTInterfaceEnabled: true

只需使用
mongod--rest启动服务器

注意:默认情况下,由于安全问题,RESTAPI不可访问。可以通过
localhost:
访问web界面,其中的数字比mongod端口的数字多
1000
。例如,您的mongodb服务器在
27017运行(默认情况下),然后您可以在

http://127.0.0.1:28017/<db-name>/<collection-name>/
http://127.0.0.1:28017///

当您使用命令
mongod
启动服务器时,使用命令
mongod
添加
--rest
选项,如下所示
mongod--rest

参考

run命令完成后,您可以使用以下简单的Restful API:

http://127.0.0.1:28017/databaseName/collectionName/

是简单的RestFul API文档。

确保.config文件中没有选项卡,否则Mongo将无法启动。它只允许空格。此外,在:FYI:for
Fedora
之后应该有空格。文件位于
/etc/mongod.conf
\o/