mongodb - SocketException 错误代码:48 允许 MongoDB 远程连接时
问题描述
我有一个运行 Ubuntu 的 AWS ligthsail 服务器。我刚刚安装了 MongoDB,它在本地运行良好。现在我想使用端口 27017 远程打开它。我已经将该端口添加到Networking
AWS 控制台上的列表中,并将我的公共 IP 添加到配置文件中。
这是我运行 mongo 的命令:
sudo mongod --fork --config /etc/mongod.conf
这是我遇到的错误:
2020-04-07T11:40:24.424+0000 I CONTROL [initandlisten] allocator: tcmalloc
2020-04-07T11:40:24.424+0000 I CONTROL [initandlisten] modules: none
2020-04-07T11:40:24.424+0000 I CONTROL [initandlisten] build environment:
2020-04-07T11:40:24.424+0000 I CONTROL [initandlisten] distmod: ubuntu1804
2020-04-07T11:40:24.424+0000 I CONTROL [initandlisten] distarch: x86_64
2020-04-07T11:40:24.424+0000 I CONTROL [initandlisten] target_arch: x86_64
2020-04-07T11:40:24.424+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0,my-remote-ip", port: 27017 }, processManagement: { fork: true, timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "the-path-to-the-db", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2020-04-07T11:40:24.424+0000 E STORAGE [initandlisten] Failed to set up listener: SocketException: Cannot assign requested address
2020-04-07T11:40:24.425+0000 I CONTROL [initandlisten] now exiting
2020-04-07T11:40:24.425+0000 I CONTROL [initandlisten] shutting down with code:48
这是 mongod 的配置:
storage:
dbPath: the-path-to-the-db
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0,<my-public-ip>
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
另外,我检查了正在运行的进程。MongoDB 未运行。我确信我也在 SO 和 Google 上搜索,但找不到任何东西。有人可以指导我解决这个问题吗?谢谢!
解决方案
好的。我添加了
security:
authorization: "enabled"
到配置文件,然后ipteables
使用以下命令进行配置
sudo iptables -A INPUT -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
显然在 AWS UI 上打开端口是不够的。
推荐阅读
- c# - 使用 Linq IQueryable,根据同一张表中的另一个字段设置过滤哪个字段
- python-3.x - 如何制作一个包含来自数据框特定列的记录的新数据框?
- c# - 如何在 OwinSelfHost 中使用 ActionFilter
- excel - 如何使用 ActiveSheet 变量?
- angular - 单行角度的多个cli命令
- c# - 错误:26 - 查找指定的服务器/实例时出错,提供程序:SQL 网络接口
- javascript - 如何根据 Id 在对象中插入键
- python - 如何从 asyncio 函数传播异常?
- google-cloud-dataflow - 如何安排 Google Dataflow SQL 作业
- mysql - 如何在确保查询已优化的同时获取相关表中的最新条目