连接linode mongodb服务器时出现连接错误
我已经安装了mogodb linode“mongodb-app”及其运行..创建的用户和集合并能够从shell访问它 现在尝试从本地连接到服务器但服务器超时 '''
pymongo.errors.ServerSelectionTimeoutError: 170.187.248.15:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 6218a8cccb94c35a2569ce55, topology_type: Single, servers: [<ServerDescription ('170.187.248.15', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('170.187.248.15:27017: timed out')>]>
default_config = {'MONGODB_SETTINGS': {
#Local DB
'db': 'test_db',
'host': 'localhost',
'port': 27017
#linode "mongodb-app"
'db': '<db name>',
'host': '<server ip>',
'port': 27017,
'username': '<db user>,
'password': '<db password>',
'authentication_source': 'admin'
}
''' 我遵循了几个步骤: '''
1. updated /etc/mongod.conf from the server
net:
port: 27017
bindIp:0.0.0.0
'''
2. sudo ufw status
sudo: unable to resolve host 170-187-248-15
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
27017 ALLOW 0.0.0.0
22 (v6) ALLOW Anywhere (v6)
但仍然面临同样的错误
I have installed mogodb linode "mongodb-app" and its running .. created user and collections and able to access it from shell
now trying to connect to the server from my local but getting server timeout
'''
pymongo.errors.ServerSelectionTimeoutError: 170.187.248.15:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 6218a8cccb94c35a2569ce55, topology_type: Single, servers: [<ServerDescription ('170.187.248.15', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('170.187.248.15:27017: timed out')>]>
default_config = {'MONGODB_SETTINGS': {
#Local DB
'db': 'test_db',
'host': 'localhost',
'port': 27017
#linode "mongodb-app"
'db': '<db name>',
'host': '<server ip>',
'port': 27017,
'username': '<db user>,
'password': '<db password>',
'authentication_source': 'admin'
}
'''
I have followed couple of steps :
'''
1. updated /etc/mongod.conf from the server
net:
port: 27017
bindIp:0.0.0.0
'''
2. sudo ufw status
sudo: unable to resolve host 170-187-248-15
Status: active
To Action From
-- ------ ----
22 ALLOW Anywhere
27017 ALLOW 0.0.0.0
22 (v6) ALLOW Anywhere (v6)
but still facing the same error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在运行 mongodb 的 Linux 服务器上,运行以下两个命令:
iptables -A INPUT -s; -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d; -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
取自 https://docs.mongodb.com/manual/tutorial/configure-linux-iptables-firewall/#traffic-to-and-from-mongod-instances
On your linux server where mongodb is running, run these two commands:
iptables -A INPUT -s <ip-address-of-your-app> -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -d <ip-address-of-your-app> -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
Taken from https://docs.mongodb.com/manual/tutorial/configure-linux-iptables-firewall/#traffic-to-and-from-mongod-instances