【问题标题】:MongoDB fails starting as a service on CentOS 7MongoDB 无法在 CentOS 7 上作为服务启动
【发布时间】:2018-02-05 18:18:47
【问题描述】:

我有一个运行了数月的带有 MongoDB 服务器的 Google 云虚拟机。今天虚拟机重新启动,MongoDB 不会作为服务运行(我可以将它作为进程手动运行并正常启动)。

  • 操作系统:CentOS 7
  • MongoDB 版本:3.2.16

抛出的错误

>sudo service mongod start

Starting mongod (via systemctl):  Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
                                                           [FAILED]

所以如果我运行“systemctl status mongod.service”:

>sudo systemctl status mongod.service

mongod.service - SYSV: Mongo is a scalable, document-oriented database.
   Loaded: loaded (/etc/rc.d/init.d/mongod; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2018-02-05 18:05:49 UTC; 1min 20s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3755 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=1/FAILURE)

Feb 05 18:05:49 todoturnos-testing systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Feb 05 18:05:49 todoturnos-testing runuser[3762]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Feb 05 18:05:49 todoturnos-testing mongod[3755]: Starting mongod: [FAILED]
Feb 05 18:05:49 todoturnos-testing systemd[1]: mongod.service: control process exited, code=exited status=1
Feb 05 18:05:49 todoturnos-testing systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
Feb 05 18:05:49 todoturnos-testing systemd[1]: Unit mongod.service entered failed state.
Feb 05 18:05:49 todoturnos-testing systemd[1]: mongod.service failed.

如果我运行“journalctl -xe”

>sudo journalctl -xe

Feb 05 18:09:58 todoturnos-testing sudo[3827]: janokpodelmundi : TTY=pts/0 ; PWD=/usr/lib/tmpfiles.d ; USER=root ; COMMAND=/sbin/service mongod start
Feb 05 18:09:58 todoturnos-testing polkitd[348]: Registered Authentication Agent for unix-process:3847:870363 (system bus name :1.242 [/usr/bin/pkttyagent --notify-fd 5 --fallback], object path /or
Feb 05 18:09:58 todoturnos-testing systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
-- Subject: Unit mongod.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mongod.service has begun starting up.
Feb 05 18:09:58 todoturnos-testing runuser[3860]: pam_unix(runuser:session): session opened for user mongod by (uid=0)
Feb 05 18:09:58 todoturnos-testing runuser[3860]: pam_unix(runuser:session): session closed for user mongod
Feb 05 18:09:58 todoturnos-testing mongod[3853]: Starting mongod: [FAILED]
Feb 05 18:09:58 todoturnos-testing systemd[1]: mongod.service: control process exited, code=exited status=1
Feb 05 18:09:58 todoturnos-testing systemd[1]: Failed to start SYSV: Mongo is a scalable, document-oriented database..
-- Subject: Unit mongod.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mongod.service has failed.
-- 
-- The result is failed.
Feb 05 18:09:58 todoturnos-testing systemd[1]: Unit mongod.service entered failed state.
Feb 05 18:09:58 todoturnos-testing systemd[1]: mongod.service failed.
Feb 05 18:09:58 todoturnos-testing polkitd[348]: Unregistered Authentication Agent for unix-process:3847:870363 (system bus name :1.242, object path /org/freedesktop/PolicyKit1/AuthenticationAgent,
Feb 05 18:10:00 todoturnos-testing sudo[3866]: janokpodelmundi : TTY=pts/0 ; PWD=/usr/lib/tmpfiles.d ; USER=root ; COMMAND=/bin/journalctl -xe
lines 2280-2321/2321 (END)

“janokpodelmundi”是我的用户名。

所以,我已禁用 SELINUX,因为我知道它可能与此问题有关,但没有解决。 我还更改了“pid”文件位置以确保权限正常,并且在配置中也禁用了分叉。

我的 mongodb 配置

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

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

# how the process runs
processManagement:
  fork: true  # fork d run in background
  pidFilePath: /var/run/mongo/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 27017
 bindIp: 0.0.0.0   # Listen to local interface only, comment to listen on all interfaces.

mongodb 日志为空,任何时候都不生成行。

我一直在尝试我在互联网上找到的许多替代方案,但问题仍然存在。

任何帮助都会很棒。

解决方案: 在尝试“mongod -f /path-to-config-file”并在第 29 行得到“不正确的 YAML”错误后,我从原始 mongo conf 粘贴了第 26-29 行:

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0  #

之后我再次尝试“mongod -f path-to-config-file”并成功。

【问题讨论】:

  • 您是否尝试过在禁用分叉的情况下从命令行mongod -f <path_to_conf>/conf_file_name.conf 启动mongod
  • 应该是systemLog:,你漏掉了一个s,或者这只是一个错字...
  • 我在这里粘贴了一个错字...配置文件的“systemLog”正确。我用配置文件尝试了 mongod -f,它抛出以下错误:解析 YAML 配置文件时出错:yaml-cpp:第 29 行错误,第 2 列:未找到地图结尾
  • @*.com/users/7174775/trdrake 您是否在 YAML 文件中使用空格而不是制表符?似乎您的 conf 文件中有一个有趣的字符或缩进。最简单的调试方法是从一个基本的 conf 文件开始并添加选项,并确保在添加另一个选项之前您的缩进等是正确的
  • 也许用 YAML 错误更新你的 OP :-)

标签: mongodb centos


【解决方案1】:

YAML 文件需要空格而不是制表符。似乎您的 conf 文件中有一个有趣的字符/缩进。最简单的调试方法是从一个基本的 conf 文件开始并添加选项,并确保您的缩进等在添加另一个选项之前是正确的

【讨论】:

    【解决方案2】:

    如上所述,问题可能是因为文件不是 Yaml 格式 跑 : mongod -f /etc/mongod.conf

    你会在哪一行得到问题(修复多余的空格,问题就会得到解决)

    【讨论】:

      最近更新 更多