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.
Related
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.
I have tried to connect to my mongodb on a server i own via an ssh tunnel via the following apps but nothing will connect:
compass
robomongo
nosqlbooster4mongo
phpstorm inbuilt mongodb java connector
Server and mongo:
Server: ubuntu 18lts
Mongo: latest community version
The Connection URL in all instances is the same (also tried removing the query params) and this url works on the node app:
mongodb://localhost:27017/data-aggregator?retryWrites=true&w=majority
nosqlbooster4mongo's error message is:
But the connection url is 27017 and gets changed to 37903 for some reason
PHPStorm's error message is:
DBMS: Mongo DB Case sensitivity: plain=mixed, delimited=mixed Driver:
MongoDB JDBC Driver (ver. 1.13, JDBC4.2) Effective version: UNKNOWN
(ver. 0.0) Ping: 10 sec, 289 ms (keep-alive query results in error)
Timed out after 10000 ms while waiting to connect. Client view of
cluster state is {type=UNKNOWN, servers=[{address=localhost:42865,
type=UNKNOWN, state=CONNECTING,
exception={com.mongodb.MongoSocketReadException: Exception receiving
message}, caused by {java.net.SocketException: Connection reset}}].
Nothing works but i cannot understand why.
The SSH connection is working as confirmed by nosqlbooster4mongo and phpstorm
But as soon as it then tries to connect to the local mongodb instance it fails. I don't know if this is an issue with the SSH tunnel or the mongo setup. Via a terminal i can connect to mongo no issue, also the node app there can too.
The tunnels are using the same key as i use to connect to the server via terminal without issue which leads me to believe it is mongo but i don't know where to look :/
As the tunnel is established, then this says the server firewalls are not an issue.
I don't know what it is, is there an additional query param for ssh tunnel access?
Solved by #Jack_Woehr on: https://www.mongodb.com/community/forums/t/mongo-5-community-edition-cannot-connect-via-tunnel/151526
The trick was to not use the ssh tunnel from any of the tools listed and just create a the tunnel on the OS.
I'm trying to connect from MongoDB compass to my database which is on VPS. MongoDB itself is working on the VPS. As well I allow firewall to connect from my IP. But it's still doesn't allow me to go. Error - connect ECONNREFUSED "ipaddress:port"
I also tried to use SSH tunnel with the same IP and port and I'm getting confused which SSH username and SSH password I need to use?
I'm using Ubuntu 18.04 on my VPS.
I checked so many resources on how to connect but doesn't find any helpful. First the problem was with Firewall and allowance of ports and IP. But now i'm 100% sure that I allow it in firewall.
For SSH Hostname - I use my IP
SSH Tunnel port - I use port which I allow
GOAL: Any solution how I can connect my MongoDB which is on VPS to MongoDB Compass? I'm really clueless on how to get it.
EDIT1
This error I receive after I'm trying to connect with MongoDB Compass -
Error creating SSH Tunnel: (SSH) Channel open failure: Connection refused
When I change the port I receive this error - Error creating SSH Tunnel: connect EADDRINUSE
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.
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.