我无法通过 systemctl 启动 MongoDB。
当我尝试时,出现错误,但日志中没有任何内容。
当我尝试通过 table_name
手动运行它时,日志中没有出现错误消息。
当我关闭登录 mongod.conf 时,会出现一条错误消息,指出我无权访问包含数据的目录(这是意料之中的)。
但是,我可以使用 sudo 启动该过程,例如:
$ /usr/bin/mongod --config /etc/mongod.conf
,进程运行但它绑定到我的终端,所以如果我的会话关闭,MongoDB 也会关闭。这就是为什么我试图用 systemctl 运行它。
然后当我尝试在我的服务中使用 sudo 运行时,例如:
$ sudo /usr/bin/mongod --config /etc/mongod.conf
然后它不会启动并且没有错误日志通过。
我的配置文件:
ExecStart=/usr/bin/sudo /usr/bin/mongod --config /etc/mongod.conf
我的服务:
# mongod.conf
# for documentation of all options, see:
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
所以它变成了一个不可能的问题。当我尝试通过 systemctl 启动它时,[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
Restart=always
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/sudo /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 mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
没有错误日志。如果我手动运行它,我会收到一条错误消息,指出我无权访问数据文件夹,因为数据文件夹归 /var/log/mongodb/mongod.log
用户所有,这是预期的。
我该怎么做才能查看导致我的上述服务失败的原因?我不想在我的 ExecStart 命令中使用 sudo,但无论我是否使用,我都会遇到同样的问题:服务无法启动,并且我的 Mongo 日志文件中没有日志。
答案 0 :(得分:2)
检查您的服务失败
systemctl is-failed mongodb.service
获取失败日志
<块引用>Journalctl 是一个实用程序,用于查询和显示来自 systemd 日志服务 journald 的日志。
获取最新的 20 行日志,这将是您失败的详细信息
journalctl | grep mongod | tail -n20
使用 journalctl -u service
和 tail 获取前 20 条日志
journalctl -u mongodb.service | tail -n20
获取所有失败服务的列表
systemctl list-units --failed
阅读 - https://www.cyberciti.biz/faq/systemd-systemctl-list-all-failed-units-services-on-linux/