20

Following this guide to install mongodb but mongo only not starting.

When running sudo systemctl status mongodb It just shows Active: failed (Result: exit-code).

Edit:

output of ls -al /etc/systemd/system/mongodb.service

-rw-r--r-- 1 root root 220 Feb 17 23:59 /etc/systemd/system/mongodb.service

output of cat /etc/systemd/system/mongodb.service

[Unit]
Description=High-performance, schema-free document-oriented >database
After=network.target

[Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install] WantedBy=multi-user.target

output of mongod

2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] MongoDB starting : pid=6617 port=27017 dbpath=/data/db 64-bit host=sherrie-HP-Pavilion-x360-m3-Convertible
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] db version v3.2.12
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] git version: ef3e1bc78e997f0d9f22f45aeb1d8e3b6ac14a14
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] allocator: tcmalloc
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] modules: none
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] build environment:
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten]     distmod: ubuntu1604
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten]     distarch: x86_64
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2017-02-18T10:19:55.072+0200 I CONTROL  [initandlisten] options: {}
2017-02-18T10:19:55.137+0200 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-02-18T10:19:55.155+0200 I STORAGE  [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2017-02-18T10:19:55.155+0200 I CONTROL  [initandlisten] dbexit:  rc: 100
842Mono
  • 9,790
  • 28
  • 90
  • 153
  • You followed ALL of the instructions at the link you provided, yes? Check that you properly created mongodb.service and it has the proper file permissions/ownership (644 root root) on it, and issued the sudo systemctl start mongodb command. Then do the sudo systemctl status mongodb command again, and edit your question to show us the output. – heynnema Feb 18 '17 at 01:35
  • @heynnema did everything except the permissions part. Can you tell me how exactly should I change permissions? Of what files? I'm not good with the permissions thing. Unfortunately the computer with the problem is not mine so I can't show outputs at the moment. thx – 842Mono Feb 18 '17 at 02:21
  • Edit your question to include the output, from terminal, of ls -al /etc/systemd/system/mongodb.service and cat /etc/systemd/system/mongodb.service – heynnema Feb 18 '17 at 02:24
  • @heynnema like I said, I currently don't have the device with the problem. It's for a friend. I'll try to show the output as soon as we meet. ...To what files should I do permission changes? How? – 842Mono Feb 18 '17 at 02:27
  • Until I see the output of those four commands, I can't tell you. – heynnema Feb 18 '17 at 02:34
  • @heynnema edited in the outputs – 842Mono Feb 18 '17 at 06:15
  • @heynnema also added the output of mongod – 842Mono Feb 18 '17 at 06:21

4 Answers4

21

Only a simple reinstall worked. Edit: MongoDB installation link. Another MongoDB installation link.

Edit: below a copy of installation commands for Ubuntu 22.04, not tested.

sudo apt-get install gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Edit: installation instructions command line block below might appear outdated.

sudo apt purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt update
sudo apt-get install -y mongodb-org

and double-check the config file:

sudo nano /etc/systemd/system/mongodb.service

paste this:

[Unit]
Description=High-performance, schema-free document-oriented >database
After=network.target

[Service] User=mongodb ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install] WantedBy=multi-user.target

finally

sudo systemctl start mongodb
sudo systemctl enable mongodb

also I think I changed the permissions of a file (a log file?) to 777.

edit:

The shell command sudo mongod --config /etc/mongod.conf should run MongoD with no service file. However, if the shell is closed, for example by closing the shell window, MongoD should exit. Shell or shell window should stay running.

To run MongoD in background, passing -b to sudo in the command should work. Appears sudo option.

sudo -b mongod --config /etc/mongod.conf

...and then, to exit the command, using the killall command might work.

842Mono
  • 9,790
  • 28
  • 90
  • 153
  • You should probably cat /etc/apt/sources.list.d/mongodb-org-3.2.list and make sure it doesn't have the deb line twice. If so, you'll need to edit it gksudo gedit /etc/apt/sources.list.d/mongodb-org-3.2.list – heynnema Feb 18 '17 at 13:06
  • it looks fine. thx @heynnema – 842Mono Feb 20 '17 at 03:58
  • 1
    For me it was that the permissions of the log file were for root, and not for my mongodb user/group. – Cryptite Feb 28 '18 at 17:45
  • 1
    I didnt even have the file sudo nano /etc/systemd/system/mongodb.service in spite of having followed the official installation instructions exactly. Creating it and pasting did the trick. No way I would have figured that out own my own. – Stonecraft Nov 12 '18 at 18:03
  • 2
    what is the difference between mongod and mongodb? – cryanbhu Jun 10 '19 at 06:01
  • What worked for me , finally is sudo systemctl enable mongodb, then i did sudo systemctl start mongodb, and finally mongodb server starts working , and running fine – arpit1714 Oct 11 '21 at 15:07
17

This Worked for me.

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

I am using Linux Mint 20.

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

sudo systemctl restart mongod
sudo systemctl status mongod

these permission commands work for me on ubuntu 20.04

hakki
  • 306
  • 3
  • 4
0

I run this command

mongod --auth --fork

because I had created admin user in admin DB before and then ran in this problem.