远程计算机的Pymongo连接超时

问题描述 投票:4回答:2

我有一个在AWS EC2上运行的Bitnami MEAN Stack。我正在尝试使用PyMongo从远程计算机进行连接。

from pymongo import MongoClient
conn = MongoClient('mongodb://username:[email protected]:27017/dbname')

但是我仍然在pymongo.errors.ConnectionFailure: timed out的地方出现错误

我已经编辑了/opt/bitnami/mongodb/mongodb.conf,以允许通过注释掉bind_ip = 127.0.0.1和未注释的bind_ip = 0.0.0.0以及注释/取消注释这些行的所有排列来允许外部连接。

我已经在网上浏览了大约90分钟,现在尝试各种尝试但没有运气!

python mongodb amazon-ec2 pymongo bitnami
2个回答
6
投票

在mongoDB服务器上,进行端口连接测试,并确保数据库服务运行良好。如果没有,请启动该服务。

telnet ec2blah.us-east-1.compute.amazonaws.com 27017

在远程计算机上,进行端口连接测试,以确保没有防火墙问题。

telnet ec2blah.us-east-1.compute.amazonaws.com 27017

如果连接有问题,则需要对此实例进行检查security groups

Click the ec2 instance name --> Description --> view rules, you should see the ports are opened

If not, create a new security group , such as `mongoDB`, tcp port 27017 should be opened for inbound traffic, then assign to that instance. 

您现在可以连接它了。


0
投票

在启动MongoDB时,将bind_ip参数设置为::,0.0.0.0

mongod --bind_ip ::,0.0.0.0

在此处阅读更多:https://docs.mongodb.com/manual/core/security-mongodb-configuration/

© www.soinside.com 2019 - 2024. All rights reserved.