1

So I am currently trying to setup mongodb running and hosting locally for my centos machine. But when I try to connect I get this:

#mongo
MongoDB shell version v3.4.24
connecting to: mongodb://127.0.0.1:27017
2021-04-20T22:06:51.585+0000 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2021-04-20T22:06:51.585+0000 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed

I've read a lot about it now.

  • User mongod is ownerr of /var/lib/monogodb
  • File /var/lib/mongodb/mongod.lock doesn't exist
  • Restarting the server caused this issue.

I think (personally) think it's something to do with iptables somehow. When I start mongodb service I get this:

# service mongod status
Redirecting to /bin/systemctl status mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2021-04-20 22:05:26 UTC; 27s ago
     Docs: https://docs.mongodb.org/manual
  Process: 1772 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=51)
  Process: 1770 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 1768 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 1766 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)

Apr 20 22:05:25 Server-Elf systemd[1]: Starting MongoDB Database Server...
Apr 20 22:05:25 Server-Elf mongod[1772]: about to fork child process, waiting until server is ready for connections.
Apr 20 22:05:25 Server-Elf mongod[1772]: forked process: 1774
Apr 20 22:05:26 Server-Elf mongod[1772]: ERROR: child process failed, exited with error number 51
Apr 20 22:05:26 Server-Elf systemd[1]: mongod.service: Control process exited, code=exited status=51
Apr 20 22:05:26 Server-Elf systemd[1]: mongod.service: Failed with result 'exit-code'.
Apr 20 22:05:26 Server-Elf systemd[1]: Failed to start MongoDB Database Server.

Iptables setup:

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     icmp --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere             state NEW tcp dpt:ssh
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
REJECT     all  --  anywhere             anywhere             reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

/etc/mongod.conf shows this: net: bindIp: 127.0.0.1

The error continues even after stopping iptables tho.. I'm so lost Help would be GREATLY appreciated. Thank you so much in advance

5
  • 2
    Your log shows errors during service startup, meaning you can't connect to a non-running process. Look into this line ERROR: child process failed, exited with error number 51 and try to find something about error 51 for mongodb Apr 21, 2021 at 4:52
  • I found one "solution" Editing the /etc/mongo.conf with "nojournal = true" then it shows error 2 instead of 51.
    – Mr.Dobby
    Apr 21, 2021 at 6:45
  • If you care about the data you should keep the journal activated. Is this a new setup? Do you need the data from the mongo database? Apr 21, 2021 at 14:20
  • What is the full story? What are the recent changes, or events? Apr 21, 2021 at 14:22
  • Changes in iptables for obvious reasons. And after a reboot the connection was denied. Even stopping iptables from running didn't get it back on track tho
    – Mr.Dobby
    Apr 21, 2021 at 14:45

1 Answer 1

0

Annoying, but only work around: Restore old backup of entire server.

While this is obviously not ideal, I could not find a way to re-open access to 127.0.0.1:27017

Some data lost, but oh well, I had backup of most of it - just setting it up again now.

Thanks for the help/advice yall.

1
  • The problem was not the connection, bu the fact that service was failing to start. It was either a permission issue or a DB corruption. Apr 21, 2021 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.