0

I suddenly cannot connect to my database! This issue occurred out of nowhere just the other day and I have not been able to figure out why.

I have pm2 processes running that are using the database and are working correctly. However, if I restart one of the process's, it will stop working with the database. This and the fact that I am unable to connect through atlas/compass are my issues.

I did recently start a mastodon on my VPS which could be (I think it is) the reason why my mongodb has encountered issues. I messed with a lot of different settings including some port stuff; I think this is where my issue may lie.

A friend of mine believes this is a port issue so he had me enable the default mongo port (27017) with ufw using the commands below:

sudo ufw allow 27017
sudo ufw allow 27017/tcp

After some in depth research, I have not yet been able to find an answer to this issue; I am praying someone here may be of help.

My mongo.conf file has not changed at all and can the start of it can be seen below:

# mongodb.conf

# Where to store the data.
dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongodb.log

logappend=true

bind_ip = 127.0.0.1,23.29.118.167
port = 27017

# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security.  Off is currently the default
#noauth = true
auth = true
Liege
  • 11
  • 1
  • `mastodon` install instructions seems to make several `iptables` rules. Can you find your connection attempts as `"iptables denied: "` entries in the log file? – rickhg12hs Dec 22 '22 at 06:29
  • Is this your real config file? Looks like you are using a very old version of MongoDB. – Wernfried Domscheit Dec 22 '22 at 06:39
  • @WernfriedDomscheit it is just the start of my config, not the entire file. – Liege Dec 22 '22 at 18:33
  • @rickhg12hs there is nothing regarding "iptables" in the log file located at `/var/log/mongodb/mongodb.log` – Liege Dec 23 '22 at 04:52
  • `iptables` logs would most likely be in the system log, perhaps `/var/log/syslog` or `/var/log/messages`. – rickhg12hs Dec 23 '22 at 04:56
  • My mistake, I thought you meant the `mongodb` logs. I cannot find the `iptables` logs anywhere. The only directories in `/var/log` are the following: `apache2, apt, caddy, dist-upgrade, installer, journal, landscape, letsencrypt, mongodb, nginx, pgadmin, postgresql, private, redis, sysstat, unattended-upgrades` – Liege Dec 23 '22 at 05:02
  • Does `journalctl -g iptables` show anything? – rickhg12hs Dec 23 '22 at 05:25
  • Yes actually, you can see below: `Dec 14 01:18:32 server-liege-dev kernel: iptables denied: IN=enp3s0 OUT= MAC=REDACTED SRC=REDACTED DST=REDACTED LEN=40 TOS=0x00 PREC=0x00 TTL=242 ID=54321 PROTO=TCP S> Dec 14 01:18:44 server-liege-dev kernel: iptables denied: IN=enp3s0 OUT= MAC=REDACTED SRC=REDACTED DST=REDACTED LEN=40 TOS=0x00 PREC=0x00 TTL=238 ID=54321 PROTO=TCP S>` I redacted some of the numbers because I do not know what they mean and I don't want to leak any of my information. – Liege Dec 23 '22 at 05:31
  • This is looking like a `iptables` configuration/rules issue. I doubt anything is wrong with MongoDB. Time to debug the firewall configuration. – rickhg12hs Dec 23 '22 at 14:11
  • Not exactly sure how to do that; is there an `iptables` command I can use to simply allow `27017` or mongo itself to allow remote access? – Liege Dec 28 '22 at 05:50

1 Answers1

1

I uninstalled and reinstalled iptables and then did iptables -F which "Delete[s] all rules in chain or all chains"

This fixed my issue, but I think I might have to reconfigure some of my iptables stuff.

Liege
  • 11
  • 1