In this paper, a personal blog address: https://www.leafage.top/posts/detail/21628W63S

Now the company’s server frequently power, so often restart all the services, but these Redis, MySQL, Mongo and other services, Mongo frequently restart the situation failed, according to the previous experience and the information posted on the network, here is a summary record;

I always recommend using yum or apt because it is clean to install and it is the same to place files in the directory (e.g. /var/log/xxx/xxx.log).

The main problems with reporting errors are as follows:

[root@localhost mongo]# systemctl mongod ● mongod.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; Vendor preset: disabled) Active: failed (Result: exit-code) since a 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... Localhost mongod[3351]: About to fork child process, waiting until server is ready for connections. Forked process: 3354 June 28 14:32:51 localhost mongod[3351]: ERROR: Child process failed, exited with 1 June 28 14:32:51 localhost mongod[3351]: To see additional information in this output, start without the "--fork" option. Mongod. service: control process exited, code=exited status=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.

If you see the occurrence of an exception, and you can’t get very effective information from it, then go to the log first. You can see some useful information in the log file (I don’t record the screenshots in time here, so I won’t put the code or the screenshots).

Processing steps:

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

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

    After the first step, execute the startup command (as shown below) with the new dbpath and logpath parameters. This will also work, but your data will be lost and you won’t be able to point to a new directory every time.

    mongod --port 27017 --dbpath /data/db  --logpath /var/log/mongod.log --fork
  2. Check if mongod.lock exists in the mongod.lock directory of mongo (default: /var/lib/mongodb). If so, delete it.
  3. Mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo. mongo.

    chown -Rc mongod. /var/log/mongodb
    
    chown -Rc mongod. /var/lib/mongo

    Once the above steps are complete, you should be able to restart the MongoDB service.