In this paper, a personal blog address: www.leafage.top/posts/detai…

At present, the company’s server is often cut off, so it is necessary to restart all services regularly. However, among these services, such as Redis, mysql and Mongo, Mongo often fails to restart. Based on previous experience and information from online posts, here is a summary.

/var/log/ XXX/XXX/XXX /xxx.log / /var/log/xxx/xxx.log

The main problems reported are as follows:

[root@localhost mongo]# systemctl status mongodLow mongod. Service - mongo Database Server the Loaded: the 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) 6月 28 14:32:51 localhost Systemd [1]: Starting MongoDB Database Server... 6月 28 14:32:51 localhost mongod[3351]: About to fork child process, waiting until server is readyforConnections. 6月 28 14:32:51 localhost mongod[3351]: forked process: 3354 6月 28 14:32:51 localhost mongod[3351]: ERROR: Child process failed, exited with 1 6月 28 14:32:51 localhost Mongod [3351]: To see additional informationin this output, start without the "--fork"Option. 6月 28 14:32:51 LocalHost Systemd [1]: mongod. Control process exited, code=exited status=1 6月 28 14:32:51 localhost systemd[1]: Failed to start MongoDB Database Server. 6月 28 14:32:51 localhost systemd[1]: 6月 28 14:32:51 Localhost Systemd [1]: Failed to enter service Entered Unit Mongod.Copy the code

When you see an exception happening, you can’t get very useful information from it. You can see some useful information in the log file. (I don’t record the screenshot in time, so I won’t show the code or screenshot.)

Processing steps:

  1. Using the repair tool provided by Mongo, execute the following command:
mongod --repair -f /etc/mongod.conf
Copy the code

After executing the first step, execute the startup command (as shown below) with the parameters pointing to the new dbPath and logPath, which will also work, but your data will be lost, and you can’t point to the new directory every time.

mongod --port 27017 --dbpath /data/db  --logpath /var/log/mongod.log --fork
Copy the code
  1. Check whether the mongod. Lock file exists in the dbpath of mongo (default: /var/lib/mongodb). If so, delete it.

  2. Mongod: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb: /var/lib/mongodb:

chown -Rc mongod. /var/log/mongodb

chown -Rc mongod. /var/lib/mongo
Copy the code

You can restart the mongodb service.