Solution to MongoDB failure

Source: Internet
Author: User
When MongoDB suddenly fails to be started, the first reaction is to delete mongod. lock. This file is in the MongoDB database directory. The default file is datadb. This is the most common problem. The cause is that MongoDB is not properly terminated (for example, killed by kill-9 or interrupted by other unexpected circumstances ). In other cases, MongoDB cannot be started. This article

When MongoDB suddenly fails to be started, the first reaction is to delete mongod. lock. This file is stored in the MongoDB database directory. The default file is/data/db. This is the most common problem. The cause is that MongoDB is not properly terminated (for example, killed by kill-9 or interrupted by other unexpected circumstances ). In other cases, MongoDB cannot be started. This article

When MongoDB suddenly fails to be started, the first reaction is to delete mongod. lock. This file is stored in the MongoDB database directory. The default file is/data/db. This is the most common problem. The cause is that MongoDB is not properly terminated (for example, killed by kill-9 or interrupted by other unexpected circumstances ).

In other cases, MongoDB cannot be started. This article discussesUnable to startIndicates to use/etc/init. d/mongodb start or sudo service mongdb start to prompt mongodb start/running, but check that the status is still stop/waiting.

Service SERVERNAME status may be a false positive. Check the actual status of MongoDB first. It is mainly ps axu | grep mongod to check whether there are any related processes. Open links or directly access 127.0.0.1: 28017 using a browser. If you do not see the MongoDB information, it indicates that it is not started.

Then execute:

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

The first command is the repair operation, and the second command is to manually specify the MongoDB configuration file and run it directly on the terminal. In this way, errors are output more intuitively without turning logs. If mongod runs smoothly, it indicates that the configuration file and database are normal. the/usr/bin/mongodb permission is insufficient. Refer to the setcap method at the end of this article.

If it cannot be run, you can see the error message in three cases: configuration file error, data directory setting error,/usr/bin/mongod file error.

The configuration file has obvious errors. If the parameter is incorrect, the error command line: unknown option xxx is displayed. The configuration file explicitly specified in the second command is also easy to troubleshoot. Therefore, except for the previous configuration file with MongoDB Master/Slave modification, the configuration file is rarely encountered.

The second is the data directory, which is mainly about permissions. The possible error is:

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

The owner of the data directory should be mongodb: mongodb.

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

The last case is/usr/bin/mongod. The error message is the same as the error message returned when the directory does not have the read/write permission. However, even if you set the database directory of MongoDB to 777, the error message is the same. Because mongod uses the O_NOATIME flag to access the file system, mongodb does not have this permission and uses setcap to set:

# Setcap cap_fowner + ep/usr/bin/mongod

If this is not the case ...... Uninstall and reinstall apt-get purge.

Original article address: the solution for MongoDB cannot be started. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.