Linking mongoDB to elasticbeanstalk application - mongodb

So I have this problem where my node application that is ran by Docker in elasticbeanstalk cant establish a connection with mongoDB instance that is in another elasticbeanstalk environment under the same application(it deployed and ran with Docker aswell).
I have made sure that both of them are in the same VPC and that the mongoDB instance accepts inbound connections from the security group that the node application is under(inbound connections are accepted on port 27017).
Node application uses mongoDBs private IP in the connection string. Should work because they are in the same VPC.
Somehow the node application cant connect to the mongoDB instance and it throws the same error always.
*** DATABASE ERROR: MongoNetworkError: failed to connect to server [private-ip-here:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND private-ip-here private-ip-here:27017] ***
Can anyone give me advice what am I doing wrong ?

Most likely reason would be not configuring mongod.config file in etc directory.
There would be something like :
net:
bindIp: 127.0.0.1
Comment the bindIP or replace it with your server's IP Address.

Related

Not able to connect to mongodb running in VM (virtual Machine) from local system

I created an AWS EC2 (ubuntu-20.04) instance and setup a mongo server as per https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-ubuntu/
(mongo server is running in default port 27017 and not secured by any username/password)
I am able to connect to it from within the VM (after connecting to VM by SSH), by running the terminal command:
mongo
I have configured EC2 instance's Security Group's inbound rule to access port 27017 from my local system's IP.
however when I try to connect to it from my local system's terminal by command:
mongo --host "<public_ip_of_vm>:27017"
Its throwing error:
connecting to:
mongodb://<public_ip_of_vm>:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server <public_ip_of_vm>:27017, connection attempt
failed: SocketException: Error connecting to <public_ip_of_vm>:27017 :: caused
by :: Connection refused : connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6 exception: connect failed exiting with code 1
Not sure what's causing this issue, I have checked the ufw rules too.
port 27017 is open.
Did you modify ?
/etc/mongod.conf
Have a look at this tutorial, especially the step 2. Maybe this helps
https://ianlondon.github.io/blog/mongodb-auth/
Connection refused means you probably do not have a firewall problem. Connection timeout indicates a firewall issue.
Since you can connect locally via localhost, the error indicates that the mongo process is only listening on localhost.
Edit the file /etc/mogod.conf. The interesting line is bindIp.
It should look like this for IPv4 only:
bindIp: 0.0.0.0
If you have IPv6 enabled
bindIp: ::,0.0.0.0
Warning: enable authentication first. You might be hacked faster than you might expect.

How to Connect using Port Forwarding Database Postgrsql on Openshift 3

I Have a problem on Connect from Port Forwarding Database on Openshift :
Running Pods Postgresql :
I Try Connect to Container running the database to check process and psql command, then it works :
Next, I Try Port Forwarding for Try Connection from outside Openshift Cluster:
Then I Try Connect from Outside Cluster to connect Postgresql have Error: Connection Refuse
Im Using IP Based or Hostname / FQDN Not Working and Error Still Exist
And When I Try Check Firewall port it has been opened port 5432/TCP :
Anyone Can Help Me With This problem ?
Thanks
Note: Before I have Been Looking Documentation but Not Working Resolve the Problem
Source Documentation:
https://www.openshift.com/blog/openshift-connecting-database-using-port-forwarding
"psql: could not connect to server: Connection refused" Error when connecting to remote database
The oc port-forward command is forwarding from only your loopback interfaces.
If you are running your client on the same machine where the cluster is running, then use localhost as your "Host".
If you are running your client on a different machine, they you need more network redirection to get this to work. Please see this post for more information as well as work-arounds for your problem: Access OpenShift forwarded ports from remote host

Mongo accepting connection but compass fails to connect

Compass fails to connect to MongoDb Server although I can see that the connection is accepted in the console and while mongo is set to listen to the right ip and port. (0.0.0.0 27017)
I have setup MongoDb in an LXD container (running on CentOs 7) inside a CentOs 7 server and I have successfully setup port forwarding from the host to the container using the following command:
lxc config device add mycontainer mongoport proxy listen=tcp:0.0.0.0:27017 connect=tcp:0.0.0.0:27017
while running MongoDb without authentication in the container using the command mongod --bind_ip 0.0.0.0 I can see that when Compass tries to make a connection to the server, the connection is actually accepted:
2019-10-16T07:33:51.008+0000 I NETWORK [listener] connection accepted from 127.0.0.1:41674 #1 (1 connection now open)
However, Compass fails to connect as it shows the following message:
Server selection timed out after 10000 ms
I am not running MongoDb with any particular configuration, and since the connection is accepted, what could go possibly wrong and cause this problem? what is the solution?
Update:
I tried disabling SElinux but it seems it has nothing to do with it.

set up Apache2 virtual hosts and now MongoDB connection refused

I'm running Ubuntu 14.04 on an AWS EC2 instance with Apache2. This morning I upgraded my Apache2 settings to allow multiple virtual servers following these instructions: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
Just now I tried to access my MongoDB instance, but I cannot do it either through the PHP MongoDB driver or through the shell. I get this error when attempting to connect with a PHP MongoClient():
Failed to connect to: localhost:27017: Connection refused'
and I get this error when trying to run the mongo shell:
2015-06-03T19:23:57.307+0000 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-06-03T19:23:57.308+0000 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
Everything was running fine just last night, and I haven't directly modified MongoDB settings. What can I do to fix this? How do Apache2 settings relate to MongoDB? I've been trying to look through the MongoDB docs, but I don't see anything that looks relevant.
You need to setup Security Group for your EC2 instance. And allow Inbound connection for the mongodb port, in your case 27017.
When I went through the logs, I saw a message that there was insufficient room for "journal file." I rebooted my AMI on an EC2 instance with more storage and reinstalled Mongo. That did the trick. I had uploaded a few files to the instance after updating my Apache2 settings, so those few more files must have pushed the instance past what Mongo could tolerate. Too bad the error message wasn't more helpful, but I should have checked the logs sooner. It would also be nice if the logs had a more explicit message.

Connecting to Mongo DB on GCE instance

I have a Google Compute Engine instance which is running an active MongoDB server. I can connect to and interact with the server on the local machine via SSH.
However, when I attempt to connect to the database instance from an external source, like my home computer, I'm getting a connection refused. I have setup a firewall rule on the default network that looks like this:
Source Ranges:
0.0.0.0/0
Allowed Protocols or Ports:
tcp:27017
udp:27017
However, even after adding this rule to the default network I am still getting a connection refused when running:
$ mongo [ipaddress]
I'm not sure why the instance is refusing the incoming connection.