mongodb not starting on ubuntu 18.04

我们两清 提交于 2021-02-10 06:49:05

问题


I'm running ubuntu 18.04 on windows 10. I run 'mongod' on cli and mongodb starts normally. I then try to run 'mongo' and I get this error :

MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-09-01T20:30:37.462+0800 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed.

I don't understand how one works and the other doesn't. I do think it is from either file permissions or an issue with the localhost.


回答1:


This might be a couple things

1.) Make sure you have the /data/db directory set up.

2.) start mongodb with sudo

sudo start mongodb 

or

sudo service mongodb start

3.) You might have to remove a lock file try the following:

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

4.) Repair your mongodb instance

sudo mongod --repair

5.) Try running the mongo console:

mongo

6.)Check the status of the mongodb instance

sudo status mongodb

If these don't work I know DigitalOcean has a great tutorial which I have linked Digital_Ocean_Tutorial




回答2:


Restart mongodb service and Verify you have installed mongo client. In case you dont, install it.

  1. sudo apt install -y mongodb
  2. sudo systemctl restart mongodb

that's it.




回答3:


First, try doing

sudo start mongodb 

If that does not work, then you can try

sudo service mongodb start

But, I would suggest do not purge or remove mongo or mongodb, as it might cause you data loss.

And if no other option remains, what you can do is copy your following folder to another directory.

Suppose ,

you take copy of the folder from

var/mongodb/lib/

and paste it to

/Downloads/db_wt_backup/

the folder has .wt (WiredTiger) files for the DB.

Then you can remove/uninstall MongoDB completely with Purge

Then re-install it again and paste the data from Downloads/db_wt_backup/ folder to var/mongodb/lib/

and then

sudo service mongodb start


来源:https://stackoverflow.com/questions/52128153/mongodb-not-starting-on-ubuntu-18-04

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!