【发布时间】:2019-07-21 19:30:00
【问题描述】:
我无法连接到在免费套餐 AWS Amazon Linux 2 AMI 上运行的 mongo 实例。我在网上浏览了几页,可以确认我做了什么,但我无法远程连接到 mongo。
- EC2(安装了 mongo)有一个公共 IP
- 使用端口 = 27017,协议 = tcp 分配的安全组(入站)
- 我可以通过 SSH 连接到 EC2(并连接到 mongo,SSH 命令如下所示)
- 我已经在 /etc/mongod.conf 文件中注释掉了绑定设置(参见下面的示例)
- 重启mongo服务,命令如下
- 本地机器 - 我可以成功 ping EC2 公共 IP
- 本地计算机 - 我尝试使用带有“mongo 1.1.1.1”的终端连接到 EC2,但收到“连接失败消息”
还有什么我可以尝试的吗? 谢谢
SSH 命令
ssh -i my-key.pem ec2-user@ec2-1-1-1-1.eu-west-2.compute.amazonaws.com
更改了 mongo 绑定设置
bindIp: 0.0.0.0
重启mongo
sudo service mongod restart
更新 - 入站规则
尝试从本地计算机连接到 mongo 时收到错误
Terminal command $ mongo 1.1.1.1
[js] Error: couldn't connect to server 1.1.1.1:27017, connection attempt failed: SocketException: Error connecting to 1.1.1.1:27017 :: caused by :: Operation timed out :
Mongo 配置文件(来自 EC2 机器)
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
security:
authorization: 'enabled'
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options
#auditLog:
#snmp:
~
【问题讨论】:
标签: mongodb amazon-web-services amazon-ec2