在 Ubuntu 16.04 服务器上启动时启动 MongoDB v3.2.10

Starting MongoDB v3.2.10 on startup on Ubuntu 16.04 server

我已经在 VirtualBox VM 上设置了 Ubuntu 16.04 服务器的全新安装。我在 NginX 中安装的唯一其他自定义应用程序。我想让 MongoDB 在服务器重新启动时自动启动。

我一直关注的官方MongoDB installation page告诉我在/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

[Install]
WantedBy=multi-user.target

但是,这个文件已经存在,条目较多,所以我没有动它。

DigitalOcean tutorial 告诉我在 /etc/systemd/system/mongod.service 创建一个内容几乎相同的文件(etc 而不是 libmongodb 而不是 mongod;缺少文档和组)。本教程还建议使用...

sudo systemctl enable mongodb

..."to enable automatically starting MongoDB when the system starts"。但是我得到这个错误:

Failed to execute operation: Invalid argument

我已经尝试了这两种技术,但是当我重新启动服务器时,MongoDB 没有启动。

我还看到有人提到 tool to create an init script at /opt/mongodb-mms-automation/bin/mongodb-mms-automation-make-init-scripts, but this was not installed when I followed the instructions on the MongoDB site

我错过了什么?

您的错误消息不是很有用,但 sudo journalctl -f -n 200 可以让您了解可能出现的问题。

您的系统上有 mongodb 用户和组吗?