Ubuntu 上的 Mongodb -'主进程已退出,代码 = 已退出,状态 = 1/FAILURE'

Mongo 突然停止在我的 Ubuntu 16.04 机器上工作,所以我试图重新启动它,但我一次又一次地遇到如下错误:

 mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Τρι 2022-03-22 12:19:53 EET; 3h 46min ago
     Docs: https://docs.mongodb.org/manual
  Process: 27559 ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf (code=exited, status=1/FAILURE)
 Main PID: 27559 (code=exited, status=1/FAILURE)

systemd[1]: Started MongoDB Database Server.
systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: mongod.service: Unit entered failed state.
systemd[1]: mongod.service: Failed with result 'exit-code'.

我修改了 mongod.conf 文件,该文件位于 /etc 中,包括以下内容:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
# engine: wiredTiger
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 23654
  bindIp: 0.0.0.0

# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

还有位于 /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 --auth --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

根据 this 帖子,我还使用以下命令更改了所有权:

sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /tmp/mongodb-23654.sock
sudo chown -R mongodb:mongodb /var/log/mongodb

我检查了文件夹并从 /var/lib/mongodb/ 中删除了 .lock 文件,现在如下所示:

 /var/lib/mongodb$ ls
    collection-0-2356690320700739995.wt   collection-2-2356690320700739995.wt  collection-8-5563536140699528517.wt  index-15-5563536140699528517.wt  index-5-5563536140699528517.wt  _mdb_catalog.wt    WiredTiger.wt
    collection-0-5563536140699528517.wt   collection-2-5563536140699528517.wt  diagnostic.data                      index-1-5563536140699528517.wt   index-6-2356690320700739995.wt  sizeStorer.wt
    collection-10-5563536140699528517.wt  collection-4-2356690320700739995.wt  index-10-2356690320700739995.wt      index-21-5563536140699528517.wt  index-7-5563536140699528517.wt  storage.bson
    collection-12-5563536140699528517.wt  collection-4-5563536140699528517.wt  index-11-5563536140699528517.wt      index-3-2356690320700739995.wt   index-9-2356690320700739995.wt  WiredTiger
    collection-14-5563536140699528517.wt  collection-6-5563536140699528517.wt  index-1-2356690320700739995.wt       index-3-5563536140699528517.wt   index-9-5563536140699528517.wt  WiredTigerLAS.wt
    collection-20-5563536140699528517.wt  collection-8-2356690320700739995.wt  index-13-5563536140699528517.wt      index-5-2356690320700739995.wt   journal                         WiredTiger.turtle

根据之前的一篇文章,我曾经从 mongod.conf 启用了 WiredTiger 引擎,但现在已将其更改回上面共享的 .conf。我应该从这个目录中删除这些文件吗?

最后,我还检查了我正在尝试使用的这个端口的防火墙,它似乎是活动的。不知道我应该解决什么我已经阅读了很多相关的帖子,但还没有完成......

stack overflow Mongodb on Ubuntu -' Main process exited, code=exited, status=1/FAILURE'
原文答案

答案:

作者头像
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /tmp/mongodb-23654.sock
sudo chown -R mongodb:mongodb /var/log/mongodb

你有用户 mongodb 吗?检查它 cat /etc/passwd |grep mongod

sudo chown -R mongod:mongod /var/lib/mongodb
sudo chown mongod:mongod /tmp/mongodb-27017.sock
sudo chown mongod:mongod /tmp/mongodb-23654.sock
sudo chown -R mongod:mongod /var/log/mongodb

可能你需要像这样-> mongod chown 他们。