MongoDB在CentOS 7上作为服务启动失败

时间:2018-02-05 18:18:48

标签: mongodb centos

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

  • OS:CentOS 7
  • MongoDB Verion: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”并成功。

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

您将了解问题所在(修复多余的空格,问题将得到解决)