连接linode mongodb服务器时出现连接错误

发布于 2025-01-10 08:43:43 字数 1292 浏览 4 评论 0原文

我已经安装了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹤仙姿 2025-01-17 08:43:43

在运行 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文