Home Database Mysql Tutorial MongoDB无法启动的解决方法

MongoDB无法启动的解决方法

Jun 07, 2016 pm 04:28 PM
mongodb start up method solve meet

遇到MongoDB突然无法启动,第一反应是删除mongod.lock。这个文件在MongoDB的数据库目录下,默认是/data/db。这是最常见的问题了,产生原因是MongoDB没有正常结束(比如被kill -9杀掉或是其他意外情况导致中断)。 还一些其他情况会导致MongoDB无法启动。本文

遇到MongoDB突然无法启动,第一反应是删除mongod.lock。这个文件在MongoDB的数据库目录下,默认是/data/db。这是最常见的问题了,产生原因是MongoDB没有正常结束(比如被kill -9杀掉或是其他意外情况导致中断)。

还一些其他情况会导致MongoDB无法启动。本文讨论的无法启动,是指:使用/etc/init.d/mongodb start或是sudo service mongdb start,提示mongodb start/running,但查看status仍然是stop/waiting。

service SERVERNAME status有可能误报,先确认MongoDB的实际状态。主要是ps axu|grep mongod查看是否有相关进程,打开links或是直接用浏览器访问127.0.0.1:28017,看不到MongoDB的信息说明没有启动。

然后执行:

$ sudo mongod --repair --config /etc/mongodb.conf
$ sudo mongod --config /etc/mongodb.conf

第一条命令是修复操作,第二条命令是手动指定MongoDB的配置文件,在终端中直接运行,这样输出错误时比较直观,不用去翻日志。如果能顺利运行mongod,说明配置文件和数据库都没有问题,是/usr/bin/mongodb权限不够,请参考本文结尾setcap方法。

如果不能运行,可以看到报错信息,分三种情况:配置文件错误,数据目录设置错误,/usr/bin/mongod文件错误。

配置文件错误比较明显,参数错误会明确提示error command line: unknown option xxx。第二条命令中明确指定使用的配置文件,也容易排错。所以除了之前配MongoDB主从修改配置文件弄坏过一次,很少遇到配置文件的问题。

其次是数据目录,主要是权限问题,可能的报错是:

Thu 22 11 10:03:30 [initandlisten] warning couldn’t write to / rename file /srv/mongodb/journal/prealloc.0
Thu 22 11 10:03:30 [initandlisten] couldn’t open /srv/mongodb/duoshuo.ns errno:1 Operation not permitted
Thu 22 11 10:03:30 [initandlisten] error couldn’t open file /srv/mongodb/duoshuo.ns terminating

数据目录的owner应该是mongodb:mongodb。

$ sudo chown mongodb:mongodb mongodb
$ sudo vi /etc/passwd

最后一种情况是/usr/bin/mongod的问题。它的报错和目录没有读写权限一样,但即使你把MongoDB的数据库目录设置成777,一样会有问题。因为mongod是以O_NOATIME标志来访问文件系统的,mongodb没有这个权限,用setcap设置:

# setcap cap_fowner+ep /usr/bin/mongod

如果这样都不行……那个apt-get purge 卸载重装吧。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. Mar 28, 2024 pm 12:50 PM

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel.

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts)

Which version is generally used for mongodb? Which version is generally used for mongodb? Apr 07, 2024 pm 05:48 PM

Which version is generally used for mongodb?

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs) May 04, 2024 pm 06:01 PM

The secret of hatching mobile dragon eggs is revealed (step by step to teach you how to successfully hatch mobile dragon eggs)

The difference between nodejs and vuejs The difference between nodejs and vuejs Apr 21, 2024 am 04:17 AM

The difference between nodejs and vuejs

How to set font size on mobile phone (easily adjust font size on mobile phone) How to set font size on mobile phone (easily adjust font size on mobile phone) May 07, 2024 pm 03:34 PM

How to set font size on mobile phone (easily adjust font size on mobile phone)

The difference between Go language methods and functions and analysis of application scenarios The difference between Go language methods and functions and analysis of application scenarios Apr 04, 2024 am 09:24 AM

The difference between Go language methods and functions and analysis of application scenarios

What are the advantages of mongodb database What are the advantages of mongodb database Apr 07, 2024 pm 05:21 PM

What are the advantages of mongodb database

See all articles