Suddenly can't connect to remote mlab mongodb - mongodb

I'm trying to connect to a remote mlab database. Everything works fine, except for some times I simply can’t connect to the database. It might have something to do with my computer since my test server can connect to it without any problems. Nevertheless I can’t figure out what the problem might be. I went through their connection troubleshooting guide but already got stuck at the first step
nc -w 3 -v ds119568.mlab.com 19568
gives the following error:
nc: connectx to ds119568.mlab.com port 19568 (tcp) failed: Operation timed out
Trying to connect via mongo shell gives this error:
MongoDB shell version v3.4.3
connecting to: mongodb://ds119568.mlab.com:19568/ba
2017-07-08T15:05:04.528+0200 W NETWORK [thread1] Failed to connect to
54.73.159.50:19568 after 5000ms milliseconds, giving up.
2017-07-08T15:05:04.533+0200 E QUERY [thread1] Error: couldn't
connect to server ds119568.mlab.com:19568, connection attempt failed :
connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6
exception: connect failed
Advice what on what could be the problem here? Does it have something to do with the firewall of my computer?

This worked for me (Ubuntu 16.04) :
sudo systemctl start mongod
Doesn't give output. Check the status to verify that the service has started properly.
sudo systemctl status mongod
Output should be something like:
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Fri 2017-02-17 18:57:26 UTC; 17min ago
Docs: https://docs.mongodb.org/manual
Main PID: 2811 (mongod)
Tasks: 17
Memory: 56.8M
CPU: 7.294s
CGroup: /system.slice/mongod.service
└─2811 /usr/bin/mongod --quiet --config /etc/mongod.conf
Verify that its running:
sudo systemctl enable mongod
Output should be:
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service
to /lib/systemd/system/mongod.service.
Then you should be able to connect to mongo shell.
mongo
For more refer to this link: https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-mongodb-on-ubuntu-16-04

Related

Mongod Process starts but Systemctl status shows failed

I have created a mongod configuration in /home/cluster1.conf with the same port I used previously for etc/mongod.conf.
I used to run etc/mongod.conf as a sudo user but expect to run cluster1.conf as user.
when I run cluster1.conf as user, the process starts. I accessed it from mongo shell and did operations. But when I'm trying to access it from another vm from the same VPC, it failed.
I checked for systemctl status mongod and it shows service is not running.
Why does systemctl status shows it not running when it really does? How can I resolve this to create a replica set??
"when I run cluster1.conf as user, the process starts." does not make much sense. cluster1.conf is a configuration file, it does not start anything.
When you run systemctl status mongod, then it typically shows
● mongod.service - MongoDB Database Server
Loaded: loaded (/etc/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2021-08-27 09:44:26 CEST; 2 weeks 3 days ago
Docs: https://docs.mongodb.org/manual
Main PID: 38710 (mongod)
Tasks: 28
Memory: 270.8M
CGroup: /system.slice/mongod.service
└─38710 /usr/bin/mongod -f /etc/mongod.conf
Check the service file /etc/systemd/system/mongod.service there you see entry like
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
Which means, config file /etc/mongod.conf is used (rather than /home/cluster1.conf)

Not able to run mongodb version 4.0 on my local machine

Getting this error when I try to run command mongo:
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-24T13:08:13.968+0800 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
After run this command sudo service mongod status Its giving me output something like this :
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: core-dump) since Sel 2018-07-24 13:18:18 +08; 45s ago
Docs: https://docs.mongodb.org/manual
Process: 18153 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=dumped, signal=ABRT)
Main PID: 18153 (code=dumped, signal=ABRT)
root#him: systemd[1]: Started MongoDB Database Server.
root#him: mongod[18153]: 2018-07-24T13:18:18.777+0800 I CONTROL [main] Automatically disabling TLS 1.0, to f
root#him: mongod.service: Main process exited, code=dumped, status=6/ABRT
root#him: mongod.service: Unit entered failed state.
root#him: mongod.service: Failed with result 'core-dump'.
The data files are created under root not the mongodb user when you run from the terminal.
You need to give permissions:
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb *
Hope this helps.
I had the same error, maybe because of ubuntu upgrade from 18.04 to 20.04. Could not start mongod manually, the reason was absence of /data/db and its permissions. Then mongod would start manually but still errorring on mongodb.service. At the end reinstalling mongodb worked. It was a new install so did not care about backups.
$ sudo apt remove mongodb mongo-tools mongodb-clients mongodb-server mongodb-server-core
$ sudo apt autoremove
$ sudo rm -rf /var/lib/mongodb/
$ sudo apt install mongodb

PG::ConnectionBad Postgres Cluster down

Digitalocean disabled my droplet's internet access. After fixing the error (rollback to older backup) they restored the internet access. But afterwards I constantly get an error when deploying, I can't seem to get my Postgres database up and running.
I'm getting an error each time I try to deploy my application.
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
So I used SSH to login to my server and check if my Postgres was actually running with:
pg_lsclusters
Results into:
Ver Cluster Port Status Owner Data directory Log file
9.5 main 5432 down postgres /var/lib/postgresql/9.5/main /var/log/postgresql/postgresql-9.5-main.log
Postgres server status
So my Postgres server seems to be down. I tried putting it 'up' again with:
pg_ctlcluster 9.5 main start After doing so I got the error: Insecure directory in $ENV{PATH} while running with -T switch at /usr/bin/pg_ctlcluster line 403.
And /usr/bin/pg_ctlcluster on line 403 says:
system 'systemctl', 'is-active', '-q', "postgresql\#$version-$cluster";
But I'm not to sure what the problem could be here and how I could fix this.
Update
I also tried updating the permissions on /bin to 755 as mentioned here. Sadly that did not fix my problem.
Update 2
I changed the /usr/bin to 755. Now when I try pg_ctlcluster 9.5 main start, I get this:
Job for postgresql#9.5-main.service failed because the control process exited with error code. See "systemctl status postgresql#9.5-main.service" and "journalctl -xe" for details.
And inside the systemctl status postgresql#9.5-main.service:
postgresql#9.5-main.service - PostgreSQL Cluster 9.5-main
Loaded: loaded (/lib/systemd/system/postgresql#.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2018-01-28 17:32:38 EST; 45s ago
Process: 22473 ExecStart=postgresql#%i --skip-systemctl-redirect %i start (code=exited, status=1/FAILURE)
Jan 28 17:32:08 *url* systemd[1]: Starting PostgreSQL Cluster 9.5-main...
Jan 28 17:32:38 *url* postgresql#9.5-main[22473]: The PostgreSQL server failed to start.
Jan 28 17:32:38 *url* systemd[1]: postgresql#9.5-main.service: Control process exited, code=exited status=1
Jan 28 17:32:38 *url* systemd[1]: Failed to start PostgreSQL Cluster 9.5-main.
Jan 28 17:32:38 *url* systemd[1]: postgresql#9.5-main.service: Unit entered failed state.
Jan 28 17:32:38 *url* systemd[1]: postgresql#9.5-main.service: Failed with result 'exit-code'.
Thanks!
You better not mix systemctl and pg_ctlcluster. Let systemctl makes the calls to pg_ctlcluster with the right user and permissions. You should start your postgresql instance with
sudo systemctl start postgresql#9.5-main.service
Also, check the errors in the startup log. You can post them too, to help you figure out what's going on.
Your systemctl status also outputs that the service is disable, so, when the server reboots, you will have to start the service manually. To enable it run:
sudo systemctl enable postgresql#9.5-main.service
I hope it helps
It is mainly because /etc/hosts file is somehow changed.I have removed extra space inside /etc/hosts file.Use cat /etc/hosts
Add these lines into the file
127.0.0.1 localhost
127.0.1.1 your-host-name
::1 ip6-localhost ip6-loopback
And I have given permission 644 to /etc/hosts file.It is working for me even after the reboot of the system.

Installing Mongo DB and get this error when start

I have followed this steps and install MongoDB in my Linux mint and finally run this command
mongo --host 127.0.0.1:27017
But got this error after run this command.
MongoDB shell version: 3.2.18
connecting to: 127.0.0.1:27017/test
2017-12-21T13:16:20.693+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2017-12-21T13:16:20.693+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:231:14
#(connect):1:6
exception: connect failed
I have already run this command also
sudo service mongod start
But after this command,
mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset:
Active: failed (Result: exit-code) since Thu 2017-12-21 13:35:28 IST; 6s ago
Docs: https://docs.mongodb.org/manual
Process: 4891 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
Main PID: 4891 (code=exited, status=100)
I found many solution but did not get it resolved. Thanks in advance.
Make sure mongod service is running locally
sudo service mongod status
and if it's not, run sudo service mongod start
If that doesn't help, try this:
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
and run service mongod start again
EDIT
Try changing permissions in the mongodb folder
cd /var/lib/mongodb
sudo chown -R mongodb:mongodb *
Also, If that doesn't help, run this
sudo /usr/bin/mongod --config /etc/mongodb.conf
and tell me the output (If it works is doesn't solve your problem, the service startup still needs to be fixed, just curious)

Downgrading MongoDB 3.4 to 3.2, can't connect to shell

I am getting this error instead of my shell prompt (running Ubuntu 16.04LTS).
I'm pretty new to MongoDB. I had to downgrade from version 3.4 to 3.2:
https://docs.mongodb.com/manual/release-notes/3.4-downgrade-standalone/
I followed those instructions (I thought) pretty faithfully, but now can't access the shell to confirm, etc.
scorpian555#scorpo:~$ mongo
MongoDB shell version: 3.2.15
connecting to: test
2017-07-13T14:41:31.434-0400 W NETWORK [thread1] Failed to connect to
127.0.0.1:27017, in(checking socket for error after poll), reason:
errno:111 Connection refused
2017-07-13T14:41:31.434-0400 E QUERY [thread1] Error: couldn't
connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
There was a socket file that the error seems to be referencing at /tmp/mongodb-27017.sock
Per these, I ended up removing that socket file, then tried to reboot the mongod daemon:
'Failed to unlink socket file" error in MongoDB 3.0
MongoDB - Permission denied for socket: /tmp/mongodb-27017.sock
service mongod restart
service mongod status
scorpian555#scorpo:~$ service mongod status
● mongod.service - High-performance, schema-free document-oriented
database
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor
preset: enabled)
Active: active (running) since Thu 2017-07-13 14:58:08 EDT; 4s ago
Docs: https://docs.mongodb.org/manual
Main PID: 4763 (mongod)
CGroup: /system.slice/mongod.service
└─4763 /usr/bin/mongod --quiet --config /etc/mongod.conf
Jul 13 14:58:08 scorpo systemd[1]: Started High-performance, schema-
free document-oriented database.
Per those, I removed the socket file and ran:
scorpian555#scorpo:~$ ls -ld /tmp
drwxrwxrwt 17 root root 20480 Jul 13 14:58 /tmp
I think I'm a little lost here, I was under the impression that, upon restart of the daemon, it would recreate this temporary file, at which point I would check the permissions.
I can't find the link at the moment, but had found elsewhere instructions to make sure the owner of the mongod.sock file was mongod (not root) and I would have to chown it if it wasn't mongod.
I'm pretty new to MongoDB, like I said. I found this as another possible issue, but wanted to see if I should dive down this rabbit hole or whether I might be looking in the wrong place?
Connection refused to MongoDB errno 111
Thanks.
My issue was that, while I started the mongod service, I did not actually run the daemon with sudo as needed.