23

I installed mongodb following this tutorial here, no errors during the installation but when I try to start the mongod server using this command sudo systemctl start mongodb as the tutorial mentions, i getting this error when i try to check whether it is running using this command sudo systemctl status mongodb.

● mongodb.service - High-performance, schema-free document-oriented 

database
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: 
   Active: failed (Result: exit-code) since Rab 2016-06-01 18:04:20 MYT; 4s ago
  Process: 8241 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
 Main PID: 8241 (code=exited, status=14)

Jun 01 18:04:20 yasinya systemd[1]: Started High-performance, schema-free docume
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Main process exited, code=e
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Unit entered failed state.
Jun 01 18:04:20 yasinya systemd[1]: mongodb.service: Failed with result 'exit-co
lines 1-10/10 (END)

so can anyone tell what is wrong and how I can fix it.

Deepam Gupta
  • 2,374
  • 1
  • 30
  • 33
Yya09
  • 283
  • 1
  • 2
  • 9
  • Check out the answer [here](http://askubuntu.com/questions/767934/mongdb-installation-failed-on-ubuntu-16-04/767965#767965), which may help you. – Shrabanee Jun 01 '16 at 10:35
  • ok let me try that thanks – Yya09 Jun 01 '16 at 10:38
  • 1
    @titi23 i got an error `Failed to start mongod.service: Unit mongod.service not found` – Yya09 Jun 01 '16 at 10:43
  • [this link](http://askubuntu.com/questions/690993/mongodb-3-0-2-wont-start-after-upgrading-to-ubuntu-15-10) may be having the solution. Try searching with the error you are getting. You will get some solution. – Shrabanee Jun 01 '16 at 10:54
  • If you were running a mongodb server and updated the system, chances are it has the “old” lock file: you can try removing it (in Ubuntu: `/var/lib/mongodb/mongod.lock`) and trying then `systemctl start mongodb.service` – Pipetus Mar 15 '18 at 00:52

14 Answers14

51

Recently i have solved the same issue. I was unable to find the solution on googled, but i get come clues to, how get figure it out. In my case this issue was related to mongodb-27017.sock file.

Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted

So i have changed the permission of /tmp/mongodb-27017.sock file to default mongodb user.

sudo chown mongodb /tmp/mongodb-27017.sock
sudo chgrp mongodb /tmp/mongodb-27017.sock

After this sudo systemctl status mongodb working fine and mongodb is started.

Ranjeet Singh
  • 662
  • 5
  • 12
35

Stumbed on the same issue, just reboot

sudo reboot
Eudie
  • 662
  • 1
  • 8
  • 17
32

This error returned by MongoDB applications which encounter an unrecoverable error, an uncaught exception or uncaught signal. The system exits without performing a clean shutdown.

I solved the problem by the command:

sudo chown -R mongodb:mongodb /var/log/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chmod -R 755 /var/lib/mongodb
sudo chmod -R 755 /var/log/mongodb

sudo chown mongodb /tmp/mongodb-27017.sock
sudo chgrp mongodb /tmp/mongodb-27017.sock

Then restart service

sudo systemctl restart mongod

Then check your mongodb service

sudo systemctl status mongod
Dara Vichit
  • 590
  • 1
  • 7
  • 15
10

I had same use ,

get solve just

sudo reboot
Sagar Jethi
  • 2,313
  • 20
  • 20
6

The first thing, you should examine the mongo log. It should tell you what went wrong.

$ tail -n 100 /var/log/mongodb/mongod.log

This command will show last 100 lines of the log file which will point you to the exact problem.

For example, mine wasn't working because i was running a mongo instance using the same port 27017. when i ran another instance, the instance failed to load.

LOG

2018-05-11T19:03:49.102-0400 I CONTROL  [initandlisten] MongoDB starting : pid=1247 port=27017 dbpath=/var/lib/mongodb 64-bit host=dev-hyuen
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] db version v3.2.20
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] git version: a7a144f40b70bfe290906eb33ff2714933544af8
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] allocator: tcmalloc
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] modules: none
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] build environment:
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     distmod: ubuntu1604
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     distarch: x86_64
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten]     target_arch: x86_64
2018-05-11T19:03:49.103-0400 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2018-05-11T19:03:49.124-0400 E NETWORK  [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 127.0.0.1:27017
2018-05-11T19:03:49.124-0400 E NETWORK  [initandlisten]   addr already in use
2018-05-11T19:03:49.124-0400 E STORAGE  [initandlisten] Failed to set up sockets during startup.
2018-05-11T19:03:49.124-0400 I CONTROL  [initandlisten] dbexit:  rc: 48
Rakibul Haq
  • 1,348
  • 23
  • 32
Hoi Yuen
  • 61
  • 1
  • 2
  • 1
    this answer cover most of the cases, running tail command on mongo db log file will show exactly what went wrong, and we can debug from there. – Rakibul Haq Mar 15 '19 at 12:19
6

Step1. sudo systemctl stop mongodb

Step2. sudo systemctl start mongod

Step3. sudo systemctl status mongod

I hope it helps you

wiomoc
  • 1,069
  • 10
  • 17
vasudev.p
  • 437
  • 1
  • 4
  • 10
3

Case with me:

  1. I installed mongodb from official site.
  2. Worked fine after installation, even worked with command-line, Robo3T and Compass.
  3. Problems occurred after rebooting once.

So, I checked the status

sudo systemctl status mongod

and got this:-

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2021-02-20 18:11:19 IST; 5s ago
       Docs: https://docs.mongodb.org/manual
    Process: 724411 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
   Main PID: 724411 (code=exited, status=1/FAILURE)

Feb 20 18:11:18 bunty systemd[1]: Started MongoDB Database Server.
Feb 20 18:11:19 bunty mongod[724411]: {"t":{"$date":"2021-02-20T12:41:19.657Z"},"s":"F",  "c":"CONTROL",  "id":>
Feb 20 18:11:19 bunty systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Feb 20 18:11:19 bunty systemd[1]: mongod.service: Failed with result 'exit-code'.

If your case is similar...

How I solved it?

  1. Check if these two directories exists or not: /var/lib/mongodb and /var/log/mongodb.

You can do this with:

test -d /var/lib/mongodb && echo "Directory Exists"
test -d /var/log/mongodb && echo "Directory Exists"
  1. The one which does not exist, make it with mkdir command.
sudo mkdir /var/lib/mongodb # run only if it does not exist
sudo mkdir /var/log/mongodb # run only if it does not exist
  1. Change owners of these directories to mongodb. Do this for both the directories.
sudo chown -R mongodb:mongodb /var/lib/mongodb 
sudo chown -R mongodb:mongodb /var/log/mongodb 
  1. Restart the mongod server.
sudo systemctl restart mongod
  1. Let's check.
sudo systemctl status mongod

If output is something like

● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-02-20 18:15:01 IST; 59min ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 734383 (mongod)
     Memory: 166.7M
     CGroup: /system.slice/mongod.service
             └─734383 /usr/bin/mongod --config /etc/mongod.conf

Feb 20 18:15:01 bunty systemd[1]: Started MongoDB Database Server.

you are good to go.

For mongo shell:

mongo

This works for me every time mongod fails, hope it works for you too.

Namaste

Deepam Gupta
  • 2,374
  • 1
  • 30
  • 33
1

I was getting the similar error, in my case mongo couldn't use 27017. I needed to stop whatever was using 27017 port and restart mongo.

Etibar - a tea bar
  • 1,912
  • 3
  • 17
  • 30
1

because the permission setting

chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock

if this worked for me after reinstalling mongodb. I have created manually

sudo mkdir /var/lib/mongodb
sudo mkdir /var/log/mongodb

and changed owner for both

sudo chown -R mongodb:mongodb /var/lib/mongodb
chown -R mongodb:mongodb /var/log/mongodb
Sagar Jethi
  • 2,313
  • 20
  • 20
0

The problem may be related to the lack of space with your /dev/root/ (it was mine).

Check with df -h and see if there enough free space. Otherwise, as explain there, try to free some space by moving the log files to another disk.

sudo /etc/init.d/rsyslog stop
sudo mv /var/log /OTHERDISK/
sudo ln -s /OTHERDISK/log /var/log
sudo /etc/init.d/rsyslog start

Hope it could help as it helps me

phenric
  • 307
  • 1
  • 8
  • 15
0

After googling around for a while. I found that that is because the permission setting on /var/lib/mongodb and /tmp/mongodb-27017.lock are wrong. You will have to change the owner to monogdb user

chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
xingliang cai
  • 241
  • 2
  • 3
0

In my case, increasing ulimit value for number of open files, solved my problem.

Like in the MongoDB docs note, if you execute ulimit -n command and the result is lower than 64000. Just execute this command: ulimit -n 128000. By the way 128000 is not a specific number. I made it up.

0

I'm using Ubuntu 20.04.5 LTS.

After trying all of the above that didn't work.

sudo apt-get install --reinstall mongodb

Reinstalling it solved the problem for me.

-1

In my case the system was not able to to find mongod.service Running the following command will fixed it

sudo systemct1 enable mongod

then restart the database by

sudo service mongod restart
Abhijeet kumar
  • 61
  • 1
  • 12