我已经在EC2上安装了MongoDB,并且在使用localhost和private_ip的相同实例中可以正常工作。但是无法从私有ip和公共ip上的同一VPC中的其他实例进行连接。也无法从我的本地计算机连接:
我的配置
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
net:
bindIpAll: true
port: 27017
我还尝试使用bindIp: 0.0.0.0
代替bindIpAll
。同时保持两者,但没有运气
日志:
2019-01-09T09:52:38.015+0530 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-01-09T09:52:38.018+0530 I CONTROL [main] Trying to start Windows service 'MongoDB'
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] MongoDB starting : pid=3540 port=27017 dbpath=c:\data\db 64-bit host=WIN-8MQFQQRJG01
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] db version v4.0.5
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] allocator: tcmalloc
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] modules: none
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] build environment:
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] distmod: 2008plus-ssl
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] distarch: x86_64
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] target_arch: x86_64
2019-01-09T09:52:38.020+0530 I CONTROL [initandlisten] options: { config: "C:\Program Files\MongoDB\Server\4.0\mongod.cfg", net: { bindIp: "0.0.0.0", bindIpAll: true, port: 27017 }, service: true, storage: { dbPath: "c:\data\db" }, systemLog: { destination: "file", path: "c:\data\log\mongod.log" } }
2019-01-09T09:52:38.021+0530 I STORAGE [initandlisten] Detected data files in c:\data\db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2019-01-09T09:52:38.021+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=256M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-01-09T09:52:38.208+0530 I STORAGE [initandlisten] WiredTiger message [1547007758:207217][3540:140735772102784], txn-recover: Main recovery loop: starting at 17/6016 to 18/256
2019-01-09T09:52:38.352+0530 I STORAGE [initandlisten] WiredTiger message [1547007758:351194][3540:140735772102784], txn-recover: Recovering log 17 through 18
2019-01-09T09:52:38.434+0530 I STORAGE [initandlisten] WiredTiger message [1547007758:434196][3540:140735772102784], txn-recover: Recovering log 18 through 18
2019-01-09T09:52:38.506+0530 I STORAGE [initandlisten] WiredTiger message [1547007758:506194][3540:140735772102784], txn-recover: Set global recovery timestamp: 0
2019-01-09T09:52:38.934+0530 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2019-01-09T09:52:38.983+0530 I CONTROL [initandlisten]
2019-01-09T09:52:38.983+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-01-09T09:52:38.983+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-01-09T09:52:38.983+0530 I CONTROL [initandlisten]
2019-01-09T09:52:39.077+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'c:/data/db/diagnostic.data'
2019-01-09T09:52:39.078+0530 I NETWORK [initandlisten] waiting for connections on port 27017
2019-01-09T09:52:39.079+0530 I STORAGE [initandlisten] Service running
我的安全组: 我试图将入站规则保留到我的IP,然后是所有IP,但仍然没有运气。
C#
var client = new MongoClient("mongodb://35.174.171.19:27017");
var db = client.GetDatabase("test");
var result = await ListAsync<BsonDocument>(db, "table1");
错误:
A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : "3", ConnectionMode : "Automatic", Type : "Unknown", State : "Disconnected", Servers : [{ ServerId: "{ ClusterId : 3, EndPoint : "35.174.171.19:27017" }", EndPoint: "35.174.171.19:27017", State: "Disconnected", Type: "Unknown" }] }.
注意:此问题的端口和凭据已打开,然后我将其保护..so无需担心测试。
答案 0 :(得分:0)
与AWS支持人员交谈后,我发现需要在实例中手动添加防火墙规则。在防火墙以及网络安全组中添加入站规则后,一切正常。我的印象是,要将端口添加到“安全”组即可。
使用netsh命令行工具运行以下命令:
netsh advfirewall防火墙添加规则名称=“ Open mongod端口27017” dir = in action = allow protocol = TCP localport = 27017