我无法连接到在免费套餐AWS Amazon Linux 2 AMI上运行的mongo实例。我已经在网上关注了几页,可以确认已完成操作,但是无法远程连接到mongo。
还有什么我可以尝试的吗? 谢谢
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:
~
答案 0 :(得分:1)
不要评论bindIp设置。如果您注释bindIp设置,它将默认为localhost。您将无法从外部网络连接。启用bindIp设置并将值设置为0.0.0.0。
还要检查入站规则IP范围和端口(27017)。
更新入站规则以接受ipv4地址(0.0.0.0/0)