Handling method of abnormal restart of Mongo service


discover problems

Now the company’s servers are often powered off, so it is necessary to restart all services regularly. However, among these redis, mysql, Mongo and other services, Mongo often fails to restart. According to previous experience and information posted on the network, here is a summary;

First of all, the services installed here are installed through Yum or apt, which is the operation I have always recommended and used, because the installation is neat and the type of files to be placed in which directory are the same (e.g.: / var / log / xxx / xxx. Log)

The main problems of error reporting are as follows:

[[email protected] mongo]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (result: exit code) since - 2021-06-28 14:32:51 CST; 6s ago
     Docs: https://docs.mongodb.org/manual
  Process: 3351 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=1/FAILURE)
  Process: 3348 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 3345 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 3343 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

June 28 14:32:51 localhost SYSTEMd [1]: starting mongodb database server
June 28 14:32:51 localhost mongod [3351]: about to fork child process, waiting until server is ready for connections
June 28 14:32:51 localhost mongod [3351]: forked process: 3354
June 28 14:32:51 localhost mongod [3351]: error: child process failed, exited with 1
At 14:32:51 on June 28, localhost mongod [3351]: to see additional information in this output, start without the "-- fork" option
June 28 14:32:51 localhost SYSTEMd [1]: mongod service: control process exited, code=exited status=1
June 28 14:32:51 localhost system d [1]: failed to start mongodb database server
June 28 14:32:51 localhost SYSTEMd [1]: unit mongod service entered failed state.
June 28 14:32:51 localhost SYSTEMd [1]: mongod service failed.

When you see the occurrence of an exception, you can’t get very effective information from it. First look at the log and you can see some useful information in the log file (if you don’t record the screenshot in time, don’t put the code or screenshot first)

Processing steps:

Using the repair tool provided by Mongo, execute the following command:

mongod --repair -f /etc/mongod.conf

Here’s an explanation. Some posts say that after the first step, execute the startup command (as follows:), which carries the parameters pointing to the new dbpath and logpath. In this way, you can also get up, but your data is lost, and you can’t point to the new directory every time.

mongod --port 27017 --dbpath /data/db  --logpath /var/log/mongod.log --fork

Check whether mongod exists in the dbpath directory of Mongo (default: / var / lib / mongodb) Lock file, if any, delete it;

Check whether the permissions of dbpath directory (default: / var / lib / mongodb) and log directory (default: / var / lib / Mongo) are mongod Mongod has operation permission. If not, give it to mongod Mongod authorization:

chown -Rc mongod. /var/log/mongodb

chown -Rc mongod. /var/lib/mongo

After the above steps are completed, the mongodb service can be restarted.


This is the end of this article on the handling of Mongo service restart exceptions. For more information about Mongo service restart exceptions, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!

Recommended Today

6、 Transaction index view cursor

1、 Business Personnel information is as follows: (the second column is the ID number, and the third column is the bank card number) –Liu Bei 420107198905064135 6225125478544587–Guan Yu 420107199507104133 6225547858741263–Zhang Fei 420107199602034138 6225547854125656 (1) Assuming Liu Bei withdraws 6000 (add check constraint, set account balance must be > = 0), it is required to use […]