【问题标题】:MongoDB aborting when running mongod command on terminal在终端上运行 mongod 命令时 MongoDB 中止
【发布时间】:2021-02-11 03:34:22
【问题描述】:

当我在 ubuntu 终端上运行 mongod 命令时,我收到此错误:

{"t":{"$date":"2020-10-28T22:27:29.341+05:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2020-10-28T22:27:29.348+05:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":9479,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"E7250"}}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.1","gitVersion":"ad91a93a5a31e175f5cbf8c69561e788bbc55ce1","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2020-10-28T22:27:29.349+05:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-10-28T22:27:29.350+05:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Operation not permitted"}}
{"t":{"$date":"2020-10-28T22:27:29.350+05:00"},"s":"F",  "c":"-",        "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919}}
{"t":{"$date":"2020-10-28T22:27:29.350+05:00"},"s":"F",  "c":"-",        "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

当我输入命令sudo systemctl status mongod时,mongod进程正在运行

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: ena>
     Active: active (running) since Wed 2020-10-28 22:02:55 PKT; 32min ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 7566 (mongod)
     Memory: 159.0M
     CGroup: /system.slice/mongod.service
             └─7566 /usr/bin/mongod --config /etc/mongod.conf

Oct 28 22:02:55 E7250 systemd[1]: Started MongoDB Database Server.

出了什么问题?

etc/mongod.conf 文件

# 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:
#  mmapv1:
#  wiredTiger:

# 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

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

【问题讨论】:

  • 从错误看来你需要以root身份执行,所以sudo mongo <something else>
  • 你能提供你的配置文件吗?
  • @WernfriedDomscheit 这个>> /etc/mongod.conf??
  • @GytisTG 与 sudo mongod 一起运行,它给出 >> {"t":{"$date":"2020-10-29T00:"2020-10-29T00:"45:01.765+05:00"},"s" :"I", "c":"CONTROL", "id":20565, "ctx":"initandlisten","msg":"现在退出"} {"t":{"$date":"2020- 10-29T00:45:01.765+05:00"},"s":"I", "c":"CONTROL", "id":23138, "ctx":"initandlisten","msg":"关闭down","attr":{"exitCode":48}}
  • @WernfriedDomscheit 我包含有问题的 mongod.conf 信息,请查看。

标签: database mongodb mongoose


【解决方案1】:

当您使用sudo systemctl start mongod 启动mongod 服务时,systemd 会读取服务文件/usr/lib/systemd/system/mongod.service

默认设置用户为mongod并读取配置文件/etc/mongod.conf

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"

当您使用 sudo mongod 启动服务时,您的 mongo 会以 root 运行,并且不会读取任何配置文件。

在默认的mongod.conf 文件中,dbPath 设置为

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true

但是,如果未提供dbPath,则应用默认/data/db

您可以使用对应于sudo systemctl start mongodsudo mongod -f /etc/mongod.conf 启动MongoDB - 但是您的mongod 以root 而不是mongod 用户身份运行。

注意,通常您不会直接在/usr/lib/systemd/system/mongod.service 文件中编辑设置。为/etc/systemd/system/mongod.service 创建一个副本并自定义此副本。见https://unix.stackexchange.com/questions/206315/whats-the-difference-between-usr-lib-systemd-system-and-etc-systemd-system

【讨论】:

    【解决方案2】:

    这对我有用:

    1. 通过在终端中输入以下命令来停止 mongod 进程:sudo systemctl stop mongod

    2. 您必须使用以下命令为“dbPath”创建目录:sudo mkdir -p /data/dbsudo chown -R `id -un` /data/db

    3. 然后运行sudo mongod --port 27017

    完成!

    您不能同时运行sudo systemctl start mongodsudo mongod --port 27017。通过sudo systemctl stop mongod 停止mongod,然后运行sudo mongod --port 27017

    希望此解决方案适用于所有有相同问题的人。

    【讨论】:

    • 反之亦然。 sudo systemctl start mongod 也应该可以工作。
    • 端口 27017 是默认端口,所以 sudo mongod 也应该可以工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-13
    • 1970-01-01
    • 2020-09-15
    • 1970-01-01
    • 2019-12-22
    • 2021-06-29
    • 2021-02-17
    相关资源
    最近更新 更多