我试图连接到我的 EC2 实例上的 MongoDB。我可以通过以下语句连接到使用公共 dns:
mongoClient = new MongoClient("ec2-3-92-197-163.compute-1.amazonaws.com", 27021);
但如果我尝试用私有 IP 地址替换“ec2-3-92 ....”,如下所示:
mongoClient = new MongoClient("172.31.90.193", 27021);
它给了我错误:
信息:连接到服务器 172.31.90.193:27021 com.mongodb.MongoSocketOpenException 时,监视器线程出现异常:在 com.mongodb.internal 的 com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) 处打开套接字时出现异常。 connection.InternalStreamConnection.open(InternalStreamConnection.java:126) at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) at java.base/java.lang.Thread.run(Thread.java: 844)由:java.net.SocketTimeoutException:在 java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:400) 处的 java.base/java.net.PlainSocketImpl.socketConnect(Native Method) 处连接超时java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:243) 在 java。base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:225) at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:402) at java.base/java.net.Socket.connect(Socket. java:591) 在 com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) 在 com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) 在 com.mongodb.internal.connection .SocketStream.open(SocketStream.java:65) ... 还有 3 个com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) 上的 SocketStream.initializeSocket(SocketStream.java:79) ... 还有 3 个com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) 上的 SocketStream.initializeSocket(SocketStream.java:79) ... 还有 3 个
线程“main”com.mongodb.MongoTimeoutException 中的异常:等待连接时在 30000 毫秒后超时。集群状态的客户端视图是 {type=UNKNOWN, servers=[{address=172.31.90.193:27021, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, 由 {java. net.SocketTimeoutException: 连接超时}}] 在 com.mongodb.internal.connection.BaseCluster.getDescription(BaseCluster.java:182) 在 com.mongodb.internal.connection.SingleServerCluster.getDescription(SingleServerCluster.java:41) 在 com .mongodb.client.internal.MongoClientDelegate.getConnectedClusterDescription(MongoClientDelegate.java:136) 在 com.mongodb.client.internal.MongoClientDelegate.createClientSession(MongoClientDelegate.java:94) 在 com.mongodb.client.internal。
我是否缺少某些东西阻止我使用私有 IP 地址连接到 mongo?
我已经设置了入站规则,如下所示:
这就是我的 mongod.conf 文件的样子:
# 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: 172.31.90.193 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
replication: replSetName: Midterm sharding: clusterRole: configsvr
## Enterprise-Only Options
#auditLog:
#snmp:
注意:我没有在我的管理员数据库集合中设置任何权限或添加凭据。