Why mongoDB built-in http stats interface on port 28017 doesn't work at all? - mongodb

Well guys, I'm trying to get that MongoDB feature working for hours:
http://www.mongodb.org/display/DOCS/Http+Interface
I start mongod with external configuration file on Mac OS X platform. Almost all the settings in the config file is default. I've turned of the authentication and make sure http interface is on :
nohttpinterface = false
MongoDB starts successfully and does it's job. And just to make sure that it listens on port 27017, I do following:
(web)Roy-MacBook:/ roy$ curl localhost:27017
You are trying to access MongoDB on the native driver port. For http diagnostic access, add 1000 to the port number
which is fine. And I try to check the same thing for the port 28017:
(web)Roy-MacBook:/ roy$ curl localhost:28017
curl: (7) couldn't connect to host
Even though with telnet:
(web)Roy-MacBook:/ roy$ telnet localhost 28017
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying fe80::1...
telnet: connect to address fe80::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
I don't know if I have to tell that I've tried with a browser. I don't run any custom web or any other server that blocks the port 28017. I could only find one bug here:
https://jira.mongodb.org/browse/SERVER-2917
but it is related with --auth command that I don't use nor I have any user show out of "db.system.users.find()".
One strange thing is when I turn on mms-name, mms-token or mms-interval in configuration as shown as their config reference here (www.mongodb.org/display/DOCS/File+Based+Configuration), mongod gives following error:
error command line: unknown option mms-name
use --help for help
I though that might be the relative problem.. Any opinion will be appreciated, thanks.

This looks like a bug in the config parser. Take this line OUT of your config file:
nohttpinterface = false
When I added that line it turned the HTTP interface off on my Mac even though it's set to false.

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.

Why can I connect to '127.0.0.1' but not 'localhost' when no internet connection is present in MongoDB compass?

I am curious why I can connect to the localhost server by specifying the loopback IP address (127.0.0.1) but not using the name 'localhost', when no internet connection is present in mongoDB compass? When I try to connect with the domain name I get the following error:
getaddrinfo ENOTFOUND localhost localhost:27017
I'm guessing the domain name lookup process is requiring the internet in order to convert localhost to 127.0.0.1. Not sure if I'm on the right track or not.
When you are connected to the internet the DNS service of your device handles the resolution of localhost. When you are not connected to the device the only way for your machine to know about the name localhost is the /etc/hosts file (or C:\Windows\System32\drivers\etc\hosts if you're running windows, latest versions of windows although might resolve localhost without using the hosts file).

Tunneling mongodb using ngrok

I have a MongoDb hosted locally in my machine and runs successfully in port localhost:27017. The database has a user name and password with a collection named, "testDb". In the code, I am able to access the database successfully using localhost.
I am trying to access this MongoDb from a remote desktop using ngrok. I hace implemented the port forwarding and the following response is shown in the command prompt.
Forwarding https://5e825c82.ngrok.io -> http://localhost:27017
I also tried changing the port =>
Forwarding https://5e825c82.ngrok.io -> http://localhost:28017
Both ports failed with the following Error message:
The connection to http://5e825c82.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:28017.
Make sure that a web service is running on localhost:28017 and that it is a valid address.
The error encountered was: dial tcp [::1]:28017: connectex: No connection could be made because the target machine actively refused it.
// Works fine
MongoClient client = new MongoClient("mongodb://admin:admin#localhost:27017/testDb");
// Fails:
MongoClient client = new MongoClient("mongodb://admin:admin#5e825c82.ngrok.io/testDb");
I would like to know how to establish a connection to the MongoDb with ngrok.
MongoDB uses TCP not HTTP.
Try following command :
ngrok tcp 27017
(note the tcp, not http which I think is what you used)
There are a couple of extra steps you need to do for some reason when you use TCP, and ngrok will prompt you and tell you what you need to do when you try the above command.
Sign up for an ngrok account at https://dashboard.ngrok.com/get-started
Run locally the command shown on this page in the box 3. Connect your account (eg. ngrok authtoken 123ABC456ETC)
Now try that command again (ngrok tcp 27017)

Not able to connect on Mongodb Atlas port

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.

Can't connect to MongoDB server on Google Compute Engine from second VM instance

I have MongoDb installed on two Ubuntu 16 VMs both hosted on the same network on Google Cloud's Compute Engine. The connecting instance has Internal IP 10.132.0.2, the database instance has 10.132.0.3.
(https://gyazo.com/59f9086591a1d6673e8194a50fff51e1)
I've opened tcp 27017 for the instance I wish to connect to. I added this using the gcloud console commands.
(https://gyazo.com/0d158aa735c6967e278fac63d598721f)
I have also tried opening tcp:1-65535;udp:1-65535 for testing purposes, with no result.
Running mongo on either instance will properly connect to it's own mongodb service, so they're installed, running and working.
On the database instance, netstat -a | grep :27017 displays that it's listening correctly.
(https://gyazo.com/0f4fb3c49a51f6886ff4ccb2d44a132a)
On the database instance, the config file at /etc/mongod.conf of the is edited so bind_ip also has the Internal IP of said instance.
(https://gyazo.com/20fb669506e7e67ef49fdcf9af6df144)
I have also tried 0.0.0.0 for testing purposes, with no result.
Running mongo 10.132.0.3 from the connecting instance results in Failed to connect to 10.132.0.3:27017, reason: errno:111 Connection refused.
(https://gyazo.com/9e5aec732e3f09cbfa62a4d78df3620f)
Running nmap -p 27017 10.132.0.3 on the connecting instance shows port 27017 is closed.
(https://gyazo.com/7ccd905db5b9946d616176b9ab75479c)
I'm at an utter loss, please help me out? :<
Your mongodb servers are only listening on the localhost address (127.0.0.1), rather than on INADDR_ANY (shows up as *:27017 in netstat).
Like this question, it looks like you need to set bind_ip = 0.0.0.0 in your mongod.conf.
Thanks to E. Anderson's link I managed to solve this issue; suddenly turning this into a duplicate. However, neither this answer nor the answer in the link were "correct".
The solution to set bind_ip=0.0.0.0 in mongod.conf is rather dangerous, besides, it didn't work. However, killing the mongodb service, and then manually running mongod --bind_ip 10.132.0.3 actually allowed my two instances to connect.
Which.. means that javadude's reply in the other thread saying "But I still dont get it. Why this did not work when I modified mongo.conf file to accept bind_ip 0.0.0.0"` also goes for me. I don't get it, but, it definitely worked to manually give it an ip-address to listen on.