我有一个运行Ubuntu的AWS ligthsail服务器。我刚刚安装了MongoDB,它在本地运行良好。现在,我想使用端口27017将其打开到远程位置。我已经将该端口添加到AWS控制台上的Networking
列表中,并将我的公共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上打开端口还不够。