无法从 systemctl 启动 mongod

无法从 systemctl 启动 mongod

我尝试从官方文档在 Ubuntu 18.04 上安装 MongoDB 5.0 社区版:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

一切都很顺利,直到我尝试运行 mongod 服务:

$ systemctl start mongod

Failed to start mongod.service: Unit mongod.service is not loaded properly: Invalid argument.
See system logs and 'systemctl status mongod.service' for details.

我尝试收集信息:

$ systemctl status mongod.service
● mongod.service
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

$ sudo systemd-analyze verify mongod.service
mongod.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
mongod.service: Failed to create mongod.service/start: Unit mongod.service is not loaded properly: Argument invalide.
Attempted to remove disk file system, and we can't allow that.

如果我尝试启用该服务,则会收到以下消息:

$ systemctl enable mongod.service
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.

事实上,如果我读取的输出systemctl list-unit-files,mongod 服务被标记为static

这是我的/lib/systemd/system/mongod.service内容(安装 mongodb 后自动写入):

  GNU nano 2.9.3                       /lib/systemd/system/mongod.service                                 

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# 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

但文件/var/log/mongodb/夹是空的。

请注意,我已经安装了以前版本的 MongoDB,因此我按照这篇文章中的步骤操作:Apt-get 在 16.04 或 18.04 上安装 mongodb 失败

之后我尝试安装 MongoDB 4.2。问题仍然存在。

它确实已经安装,我可以看到它的版本:

db version v4.2.18
git version: f65ce5e25c0b26a00d091a4d24eec1a8b3a4c016
OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1804
    distarch: x86_64
    target_arch: x86_64

这些 systemctl 错误是什么意思?我应该尝试做什么?感谢您的阅读。

编辑:请注意,我需要运行该mongod命令sudo才能使其在终端上工作。

mongod.service因此我测试了两种方法来修改该文件:

  • 首先是User=rootGroup=root
  • 然后添加mongodb到我的 sudo 组并使用:
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=sudo /usr/bin/mongod --config /etc/mongod.conf

两者都导致了同样的错误:Invalid argument

相关内容