Mongodb Service Fails After Reboot

Why Mongo Auto Restart after Shutdown

MongoDB is installed as a service.

For stop and disable use:

systemctl stop mongod
systemctl disable mongod

How to recover a standalone MongoDB after an unexpected shutdown on k8s

Here is my fix:

First

change k8s deployment.yaml config.

Because we want to repair the data file of mongodb, the first step is to make the mongo pod run, we run the command in the pod.

Now change the startup command of the container:

 containers:
- name: mongodb
image: mongo:latest
command: ["sleep"]
args: ["infinity"]
imagePullPolicy: IfNotPresent
ports:
# .......

After apply it.
If I guessed correctly, the mongo pod should be up and running.

Second

Use mongod command to repair data.

kubectl exec -it <YOURPODNAME> -- mongod --dbpath <YOURDBPATH> --repair --directoryperdb

I have to exec it with --directoryperdb, if you run it error, you can try remove it.

If I guessed correctly, So far everything is fine.

Third

Recover k8s deployment.yaml, back to the way they were.

Now reapply it.

---------- Manual split line

The above is my repair process. Its worked for me. I just record it. You can refer to it to fix your mongodb. Thank you.

mongodb not starting after reboot for my rails3 app

I think the issue is due to mongodb lock.

Try this:

sudo rm -rf /var/lib/mongodb/mongod.lock

and restart your service.



Related Topics



Leave a reply



Submit