Unable To Remote Connect To Mongo CLI. Do different versions matter? - mongodb

I have three mongo instances running where one is a higher version. The reason is that mongochat02 is a newly provisioned server and the installed version came with 3.2.9.
mongochat01 - v3.0.8
mongochat02 - v3.2.9
mongochat03 - v3.0.8
I am able to issue mongo --host between mongochat01 and mongochat03 but cannot connect to mongochat02 from either mongochat01 and mongochat03.
Below is the example attempting to connect to mongochat02 from a working instance. It says connected but it never enters the shell and just gets stuck and eventually times out.
[richlu#chat03 ~]$ mongo --host mongochat02 --verbose
MongoDB shell version: 3.2.4
connecting to: mongochat02:27017/test
2017-04-10T21:29:04.348+0000 D NETWORK [thread1] creating new connection to:mongochat02:27017
2017-04-10T21:29:04.350+0000 D COMMAND [ConnectBG] BackgroundJob starting: ConnectBG
2017-04-10T21:29:04.392+0000 D NETWORK [thread1] connected to server mongochat02:27017 (10.8.129.114)
2017-04-10T21:29:04.434+0000 D NETWORK [thread1] connected connection!
I am able to ping between the servers and nmap shows port 27017 is open for all three servers.
Firewalld shows 27017 as TCP open.
Issuing netstat -tulpn | grep 27017 gives
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 24456/mongod
The /etc/mongod.conf files are the same, except the bindIp includes the server ip. I have tried commenting out the bindIp line and tried with 0.0.0.0.
I need help figuring out why I am unable to connect to the mongochat02 through the mongo client from the other servers. Do the versions matter much in this case? I was able to connect from my local Macbook running v3.2 to mongochat01 and mongochat03 just fine.
This connection issue is not allowing mongochat02 to become a replica set member.
Any help would be appreciated.

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.

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.

Compute Engine With VPC Firewall Open Could Not Connect To Mongo Port 27017 Remotely

I installed MongoDB v3.6.4 server. I have the following settings in Google Compute Engine:
Configuration
In /etc/mongod.conf file:
net:
port: 27017
bindIp: 0.0.0.0
security:
authorization: enabled
I also did the following:
Removed mongod.lock
Created a firewall rule in VPC for both tcp:27017 and udp:27017 to be open.
Connection:
I can connect locally by:
mongo 127.0.0.1:27017/database -u myusername -p
But, I can not connect remotely using an IP address or domain by:
mongo my.ip.com:27017/database -u myusername -p
mongo <IP ADDRESS>:27017/database -u myusername -p
Error
It gives me the error:
[thread1] Failed to connect to <IP ADDRESS>:27017 after 5000ms milliseconds, giving up.
[thread1] Error: couldn't connect to server my.ip.com:27017, connection attempt failed : connect#src/mongo/shell/mongo.js:237:13
Other Things I've Tried
switched back and forth from different server versions from micro, small, and 1vCPU (thinking it was the processor)
Changed configurations over and over of the net and security
Added a static IP address.
Checked my other servers with the same setting which worked and copied from it.
Checked the logs and it does not give me anything after remotely connecting.
Checked my firewall name, which is default-mongodb for tcp:27017 and udp:27017.
None of the settings in this specific server seem to work.
Other Information
I'm connecting using Mongo client v3.4.9
Did I miss to check something? Why is it not working?
Never mind... I did not enter the range for the VPC Firewall Rule.
It should be 0.0.0.0/0 instead of just 0.0.0.0

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.

MongoDB connect error [duplicate]

I've recently installed mongodb on my CentOS 6 VM running on Vagrant.
I added port forwarding to Vagrantfile to forward the mongo port
config.vm.forward_port 27017, 127017
I configured mongod to start automatically when the server starts and have confirmed that the service starts as intended.
however when i run mongo localhost:127017 from my host machine (not vagrant) i get the following error
MongoDB shell version: 1.8.2
connecting to: localhost:127017/test
Fri Jan 20 13:58:28 getaddrinfo("127.0.0.1") failed: nodename nor servname provided, or not known
Fri Jan 20 13:58:28 Error shell/mongo.js:81
exception: connect failed
any ideas?
You will need to set the mongod bind_ip to 0.0.0.0 instead of 127.0.0.1 (which is the loopback address) so that all interfaces can access it.
TCP port numbers are 16-bit unsigned, which mean the max value is 65535 (2^16), and you're trying with 127017.
Can you connect to the mongo server from vagrant ssh? If not, you might want to make sure that mongod is running.
Do you have an ip_bind set up in your mongodb.conf or mongod startup script? (If you do, you might want to unset it--not exactly sure how vagrant's port forwarding works, but this might be what's causing the problem.)
bind_ip to 0.0.0.0 does not work. Try bind_ip=127.0.0.1,10.0.0.25, that worked for me.