mongos Socket operation timed out - mongodb

I've got a mongos router running on amazon ECS in an EC2 machine, and also hosted on a route53 hosted zone.
The thing is that I can reach the mongos service via HTTP with the record name:
https://mongos-router.awsqa.xxx.net/
With the response:
It looks like you are trying to access MongoDB over HTTP on the native
driver port.
Which means that mongos is running correctly.
The ecs logs I get shows its running correctly also.
But trying to connect to it via mongo command:
$ mongo --host mongos-router.awsqa.xxx.net
MongoDB shell version v4.4.4
connecting to: mongodb://mongos-router.awsqa.xxx.net:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server mongos-router.awsqa.xxx.net:27017, connection attempt failed: NetworkTimeout: Error connecting to mongos-router.awsqa.xxx.net:27017 (xx.xxx.xx.xx:27017) :: caused by :: Socket operation timed out :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
I've confirmed that the container port is correct also:
"portMappings": [
{
"hostPort": 0,
"protocol": "tcp",
"containerPort": 27017
}
],
a part of mongos.conf file:
net:
bindIp: 0.0.0.0
port: 27017
Dockerfile final command:
CMD [ "mongos", "--config", "/etc/mongos.conf" ]
Any idea at all to what is causing this network timeout error will be helpful

Related

Can't connect to MongoDB running in docker container

I run MongoDB in a docker container like this
docker run --name mongo -d -p 27017:27107 mongo
Check with docker ps shows
77f1a11295c3 mongo "docker-entrypoint.s…" 20 minutes ago Up 20 minutes 27017/tcp, 0.0.0.0:27017->27107/tcp mongo
so it's running with the port mapped correctly.
When I try to setup a connection via Intellij
it fails with
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Exception receiving message}, caused by {java.net.SocketException: Connection reset}}].
When I try to connect to connect from a golang web server
clientOptions := options.Client().ApplyURI("mongodb://localhost:27017")
client, err := mongo.Connect(context.TODO(), clientOptions)
I get this error and it shuts down the web server:
server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: localhost:27017, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: connection(localhost:27017[-64]) incomplete read of message header: read tcp 127.0.0.1:40700->127.0.0.1:27017: read: connection reset by peer }, ] }
Is this a bug in the MongoDB docker image, or is there something else I need to do?
I think you have a typo mistake while creating a container. 27017 and 27107
docker run --name mongo -d -p 27017:27017 mongo
This is clearly visible in docker ps command.
Can you try and see if it solves the problem ?
As #fly2matrix said you have a typo, and I believe you have another issue:
you forward the ports 27017:27107, in which the container port is incorrect. Check 27107 instead of 27017
It seems you're connecting to localhost instead of mongo as I see the phrase localhost in your code.

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27

I want to change the default port of mongodb so I did :
sudo nano /etc/mongod.conf
# network interfaces
net:
port: 27042
bindIp: 127.0.0.1
and
sudo service mongod start
But now when I want to run "mongo" I got this error:
MongoDB shell version v4.0.24
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2021-05-18T12:44:36.436+0200 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:356:17
#(connect):2:6
exception: connect failed
The message says " couldn't connect to server 127.0.0.1:27017" despite I changed the port in mongod.conf. I even tried to reboot my computer but it still not working.
UFW is not active si I don't think it's a firewall problem.
Based on your mongod.conf file, MongoDB will run on port 27042. When you run the command mongo without parameter --port, it will connect to the default port 27017 then you have the error.
I think this command mongo --port 27042 will work.

MongoDB, remote connection failing

I'm trying to connect to mongoDB server running in another AWS Account from my other AWS account to refresh the content.
I'm getting an error.
I NETWORK [thread1] Socket recv() errno:104 Connection reset by peer mongo_db_server:27017
I NETWORK [thread1] SocketException: remote: (NONE):0 error: 9001 socket exception [RECV_ERROR] server [mongodb_db_server:27017]
2021-01-14T23:26:26.015-0500 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host 'mongodb_db_server:27017' :
connect#src/mongo/shell/mongo.js:231:14
#(connect):1:6
Remote MongoDB server config has
net:
port: 27017
bindIp: 0.0.0.0
Security groups allow connection to 27017 from 0.0.0.0/0 fo testing purpose.
what am i missing?
It was due to network connectivity.

Can't login to Wekan DB CentOS console

I have recently installed Wekan on a CentOS (CentOS Linux release 7.6.1810) server and it works well. However I need to login to the MongoDB. I have followed the installation guide of MongoDB and set a password for 'admin' user. But when When the "mongo -u admin -p" command is entered it prompts for password and I get the following error. However I have another issue not starting "mongod", but it is enabled.
connecting to: test
2020-06-12T01:20:23.618-0400 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2020-06-12T01:20:23.618-0400 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
I created this user in mongo which does not seem to work when trying to login to the DB.
$ mongo
db.createUser(
{
user: "admin",
pwd: "abcd1234",
roles: [ { role: "root", db: "admin" } ]
}
)
Firstly I installed the latest version of mongodb and then I downgraded to to 3.2 which works with wekan. However Wekan still works fine without any issue.
This is the error I get when starting the mongod.
$ systemctl start mongod
Job for mongod.service failed because the control process exited with error code.
See "systemctl status mongod.service" and "journalctl -xe" for details.
$ systemctl enable mongod
mongod.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mongod on
The port mongod uses is 27019 which I found from the following command.
$ ss -nutlp
tcp LISTEN 0 128 127.0.0.1:27019 *:* users:(("mongod",pid=11578,fd=6))
What am I doing wrong here?
In the output of the mongo shell connection failure:
Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
This tells you that it is attempting to connect to port 27017 on localhost, and that the operating system actively refused the connection because nothing is listening on that port.
The ss output shows that mongod is listening on port 27019.
Try adding --port 27019 to your mongo command line.

Can't connect to MongoDb externally

Some information:
The port is indeed open(i can bind it to apache2, for example, and access it externally)
I've tried setting the bind_up parameter to 0.0.0.0, to my localip, etc
I can access it through my local IP(192.167.10.xxx)
I didn't isntall mongo with apt-get, just downloaded it and ran mongod
I've spent a lot of time searching and trying different things, anyone has a idea on what could be causing it?
Mongo runnning
edit:
Mongo options: [initandlisten] options: { config: "config.conf", net: { bindIp: "0.0.0.0", port: 8008 }, security: { authorization: "enabled" }, storage: { dbPath: "/home/defense/mongo/data" } }
When i try to connect:
[thread1] Failed to connect to 146.164.x.xxx:8008, in(checking socket for error after poll), reason: Connection refused
Port check(also I used to connect to MySql using that same port):
Port 8008 is open on 146.164.x.xxx.
Any ideas?