mongod:无法识别的服务,mongod.service 已经存在

mongod:无法识别的服务,mongod.service 已经存在

其他服务(例如 apache2 等)运行良好。但是当我输入时,sudo service mongod start出现此错误:

mongod: unrecognized service

我有这个文件:

/lib/systemd/system/mongod.service 

它说的是:

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

答案1

我在拉取 ubuntu:17:04 docker 镜像并安装 mongodb-org 后遇到了同样的问题

看起来 Mongodb 创建了一个 systemd 启动文件,该文件已被 upstart 替换。

解决方法:

  1. 创建一个新文件/etc/init/mongod.conf(需要 sudo 权限)。您可以使用:sudo gedit /etc/init/mongod.conf

  2. 将以下内容粘贴到新创建的 upstart 文件中:

    # Ubuntu upstart file at /etc/init/mongod.conf
    
    # Recommended ulimit values for mongod or mongos
    # See http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
    #
    limit fsize unlimited unlimited
    limit cpu unlimited unlimited
    limit as unlimited unlimited
    limit nofile 64000 64000
    limit rss unlimited unlimited
    limit nproc 64000 64000
    
    kill timeout 300 # wait 300s between SIGTERM and SIGKILL.
    
    pre-start script
      DAEMONUSER=${DAEMONUSER:-mongodb}
      if [ ! -d /var/lib/mongodb ]; then
        mkdir -p /var/lib/mongodb && chown mongodb:mongodb /var/lib/mongodb
      fi
      if [ ! -d /var/log/mongodb ]; then
        mkdir -p /var/log/mongodb && chown mongodb:mongodb /var/log/mongodb
      fi
      touch /var/run/mongodb.pid
      chown $DAEMONUSER /var/run/mongodb.pid
    end script
    
    start on runlevel [2345]
    stop on runlevel [06]
    
    script
      ENABLE_MONGOD="yes"
      CONF=/etc/mongod.conf
      DAEMON=/usr/bin/mongod
      DAEMONUSER=${DAEMONUSER:-mongodb}
      DAEMONGROUP=${DAEMONGROUP:-mongodb}
    
      if [ -f /etc/default/mongod ]; then . /etc/default/mongod; fi
    
      # Handle NUMA access to CPUs (SERVER-3574)
      # This verifies the existence of numactl as well as testing that the command works
      NUMACTL_ARGS="--interleave=all"
      if which numactl >/dev/null 2>/dev/null && numactl $NUMACTL_ARGS ls / >/dev/null 2>/dev/null
      then
        NUMACTL="$(which numactl) -- $NUMACTL_ARGS"
        DAEMON_OPTS=${DAEMON_OPTS:-"--config $CONF"}
      else
        NUMACTL=""
        DAEMON_OPTS="-- "${DAEMON_OPTS:-"--config $CONF"}
      fi
    
      if [ "x$ENABLE_MONGOD" = "xyes" ]
      then
        exec start-stop-daemon --start \
            --chuid $DAEMONUSER:$DAEMONGROUP \
            --pidfile /var/run/mongodb.pid \
            --make-pidfile \
            --exec $NUMACTL $DAEMON $DAEMON_OPTS
      fi
    end script
    
  3. 现在,您可以使用以下命令:

    sudo service mongod start

    sudo service mongod stop

    sudo service mongod status

参考: https://github.com/mongodb/mongo/blob/master/debian/mongod.upstart

答案2

我首先删除了 mongo lock 文件

sudo rm /var/lib/mongodb/mongod.lock

然后使用以下命令启动 mongod

sudo mongod --fork -f /etc/mongod.conf

答案3

尝试启动 mongo 服务时,我一直收到相同的错误。mongod 可以工作,但是我需要保持一个终端窗口打开才能在另一个终端窗口中使用 mongo。除了这个之外,其他方法都不起作用:

复制代码

如果你还没有启动 mongo 守护进程,上面的命令会启动它,然后你可以在命令行中输入“mongo”,mongo 就可以运行

(从这里:https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/

相关内容