Chlebta
Chlebta

Reputation: 3110

Mongo service start or restart always fail

I've installed mongodb then I've created a mongo 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

But When I launch the service and then I check the status, I get always this error:

● mongodb.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2017-04-24 13:08:55 UTC; 6min ago
  Process: 1094 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=48)
 Main PID: 1094 (code=exited, status=48)

Apr 24 13:08:54 ip-172-31-37-163 systemd[1]: Started High-performance, schema-free document-oriented database.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Main process exited, code=exited, status=48/n/a
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Unit entered failed state.
Apr 24 13:08:55 ip-172-31-37-163 systemd[1]: mongodb.service: Failed with result 'exit-code'.

Upvotes: 14

Views: 44913

Answers (5)

MTS
MTS

Reputation: 1915

Update for Ubuntu 20.04 and MongoDB server version 4.4.2...

The issue for me ended up being that I was trying to use my machine's public IP address.

Once I specified my private IP address, everything started working. The mongod service starts without any errors, and I am now able to connect to it from remote machines.

On Ubuntu, you can use the following command to get your private IP address:

hostname -I | awk '{print $1}'

Here's what I have in /etc/mongod.conf (only showing relevant sections, and partial private IP address):

net:
  port: 27017
  bindIp: 127.0.0.1, 172.##.##.##

security:
  authorization: enabled

Note that putting brackets around the two IP addresses (as in the accepted answer) did NOT work for me, and resulted in a mongod status code of 2 (effectively a syntax error in the mongod.conf file). Also the space after the comma seems to work now, though not required.

Upvotes: 1

Savio
Savio

Reputation: 101

Try changing the owner permissions

chown -R mongodb:mongodb /var/lib/mongodb

chown mongodb:mongodb /tmp/mongodb-27017.sock

Upvotes: 4

Killman
Killman

Reputation: 1

I just reboot system (sudo reboot) it is working for me. i don't know why.

Upvotes: -4

Rodrigo Pinto
Rodrigo Pinto

Reputation: 2414

In MongoDB 3.6 the brackets proposed by @Chlebta did not work for me, returning the error:

mongod.service: Main process exited, code=exited, status=2/INVALIDARGUMENT

My mistake was separating the IP addresses with commas and spaces. There has to be only commas between the addresses:

bindIp: 127.0.0.1,X.X.X.X,Y.Y.Y.Y

Upvotes: 2

Chlebta
Chlebta

Reputation: 3110

The problem was in config file and changing

bindIp: 127.0.0.1, X.X.X.X

to

bindIp: [127.0.0.1, X.X.X.X]

Solved my issue

Upvotes: 18

Related Questions