I'm using an M0 GCP instance.
I can connect to the cluster using this string:
'mongodb+srv://my_user:my_pass#my_cluster-mbsnz.gcp.mongodb.net/db?retryWrites=true&w=majority'
I'm trying to use another client where I need to pass host and port, but I can't connect.
I tried telnet to the port 27017, but for some reason I'm not able to connect directly on the port.
curl http://my_cluster-mbsnz.gcp.mongodb.net:27017
curl: (7) Failed to connect to my_cluster-mbsnz.gcp.mongodb.net port 27017: Connection timed out
or
telnet my_cluster-mbsnz.gcp.mongodb.net 27017
Trying 185.82.212.199...
^C -> After a long time waiting
What might be wrong ?
+srv urls use a DNS seed. On atlas, you can click into the cluster and you should be able to see the urls for your primary & your secondaries and use those urls to connect. You should also be able to use nslookup to get that info using part of that connection string, but it's probably simpler to just look up the urls through the UI.
https://docs.mongodb.com/manual/reference/connection-string/
In order to leverage the DNS seedlist, use a connection string prefix of mongodb+srv: rather than the standard mongodb:. The +srv indicates to the client that the hostname that follows corresponds to a DNS SRV record. The driver or mongo shell will then query the DNS for the record to determine which hosts are running the mongod instances.
Related
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
Is it possible to setup/use HAProxy to forwards requests to a mongo database? If so can someone provide a basic example of how to set this up in the haproxy.cfg file?
I tried this, but this doesn't work:
listen mongo
bind 10.123.45.6:27017
mode tcp
balance roundrobin
server mongo1 10.456.78.9:27017
Where 10.123.45.6 is the IP of instance w/ HAProxy installed.
Where 10.456.78.9 is the IP of instance w/ mongodb installed.
Screenshot when trying to invoke client via command line:
C:\Program Files\MongoDB\Server\3.6\bin>mongo "mongodb://10.123.45.6:27017"
MongoDB shell version v3.6.11
connecting to: mongodb://10.123.45.6:27017/?gssapiServiceName=mongodb
2020-01-23T15:53:41.707-0800 W NETWORK [thread1] Failed to connect to 10.123.45.6:27017 after 5000ms milliseconds, giving up.
2020-01-23T15:53:41.707-0800 E QUERY [thread1] Error: couldn't connect to server 10.123.45.6:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:263:13
#(connect):1:6
exception: connect failed
Your settings are right, however I am adding an example for you
listen port_27017
bind :27017
mode tcp
server mongodb-port 10.156.78.9:27017
It should connect, but just to confirm from where are trying to connect? Is it within the local network or somewhere from the cloud. Because as per RFC 1918 all the 10.0.0.0/8 belong to private network, if you are outside the network and trying to access the 10.123.45.6 it won't work.
And if it is within network, and try to tail the log of HAProxy and see if it is able to connect to the Mongo or not.
If it is outside, you need to connect to HAProxy using it's public IP address rather than private IP.
I have installed and running mongodb on port 27017 of my VM on gcp. But I am not able to access database from my pc or any external client.
I have set firewall rules to allow ingress traffic with tcp protocol on port 27017(tcp:27017) from all ip ranges(0.0.0.0/0) and have set priority 1000.
firewall rules snapshot
Now when i am trying to access the database from external client I am not able to access it. I even tried mongodb compass and used ip address of VM and port 27017 to access the database. But unable to connect and showing(mongodb not running on provided host and port) however I am able to access to database when accessed from that VM itself in which I have installed the mongodb.
Please suggest if I am missing out anything.
By default, MongoDB doesn’t allow remote connections. So I would suggest you follow this tutorial to resolve your issue.
Let me know if this was helpful.
Add --bind_ip_all to mongodb server start command.
When I start MongoDB using mongod.exe it displays a message like "waiting for connections on port 27017", but when I execute mongo.exe the log message is "connection accepted from 127.0.0.1:60501".
Now, when I use PyMongo to connect to the DB I assumed that the port number to be used is "60501" since this is the port where the connection was established. Surprisingly I got an error saying "connection refused". I thought there was some problem with my MongoDB installation, config file placement, etc.
When nothing fixed it, I just played around by changing the port number to 27017, and this actually fixed the problem. Can someone explain how this worked out?
This behaviour is not specific to MongoDB. As part of the TCP/IP client/server protocol, services listen on configured ports (typically with well known defaults like 27017 for mongod). Clients connect to a server port and also establish their own ephemeral/dynamic port to use for the duration of a client/server session.
Each active session from the same client IP will use a distinct port on the client. The ephemeral port is logged to identify different client connections as they are established.
The logging in your case might be slightly confusing since you are connecting from localhost (127.0.0.1) where the server is also running, but the correct port to connect to is the mongod server port (default: 27017).
I am trying to set up a MongoDB replica set on Docker follwoing this guide. However when I get to the rs.intitate() command, I get an error.
"errmsg" : "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: mongo-local-002:27017 failed with Connection refused, mongo-local-003:27017 failed with Connection refused"
edit: using latest version of docker container (3.6)
edit2: the problem is actually with mongo 3.6 (3.4 works). I have tried binding each replica ip to an ip in the docker network, however in this way I am not able to open the mongo console on the main replica (it says connection refused) even passing the IP instead of the replica name.
Does anyone know what I am missing here?
Starting in MongoDB 3.6, MongoDB binaries, mongod and mongos, bind to localhost by default. You need to start every mongod with --bind_ip. Try to bind not only a specific ip but to all IPv4. To bind to all IPv4 addresses, you can specify the bind ip address of 0.0.0.0. That way you will verify if the bind to a specific ip is the problem.