远程机器的Pymongo连接超时 [英] Pymongo connection timeout from remote machine
问题描述
我有一个在AWS EC2上运行的Bitnami MEAN Stack.我正在尝试使用PyMongo从远程计算机进行连接.
I have a Bitnami MEAN Stack running on AWS EC2. I'm trying to connect from a remote machine using PyMongo.
from pymongo import MongoClient
conn = MongoClient('mongodb://username:password@ec2blah.us-east-1.compute.amazonaws.com:27017/dbname')
但是我总是在pymongo.errors.ConnectionFailure: timed out
我已经编辑了/opt/bitnami/mongodb/mongodb.conf
,以允许通过注释掉bind_ip = 127.0.0.1
和未注释的bind_ip = 0.0.0.0
以及注释/取消注释这些行的所有排列来允许外部连接.
I have edited /opt/bitnami/mongodb/mongodb.conf
to supposedly allow external connections by commenting out bind_ip = 127.0.0.1
and uncommented bind_ip = 0.0.0.0
and all permutations of commenting/uncommenting those lines.
我在网上浏览了大约90分钟,现在尝试各种尝试但没有运气!
I've looked over the web for about 90 minutes now trying different things but without luck!
推荐答案
在mongoDB服务器上,进行端口连接测试,并确保DB服务运行良好.如果没有,请启动该服务.
On the mongoDB server, do the port connection test, and make sure the DB service running well. If not, start the service.
telnet ec2blah.us-east-1.compute.amazonaws.com 27017
在远程计算机上,进行端口连接测试,以确保没有防火墙问题.
On the remote machine, do the port connection test, to make sure there is no firewall issue.
telnet ec2blah.us-east-1.compute.amazonaws.com 27017
如果连接有问题,则需要在此实例上检查security groups
.
If you have issue to connect, you need check security groups
on this instance.
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.
您现在可以连接它了.
You should be fine to connect it now.
这篇关于远程机器的Pymongo连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!