【发布时间】:2019-02-15 13:54:38
【问题描述】:
可能是重复的here,但无法找到正确答案,因此提出了这个问题。
所以,我在本地机器上有一个mongodb 设置说M1mongo 服务正在运行并且db 有一些数据。
现在,我想在其他机器上使用 mongo 客户端连接到这个 mongodb,例如 M2,但无法连接。
根据所有答案,我尝试在mongodb.conf 文件中添加M2 地址,但没有成功。
net:
bindIp: [m2.some.valid.ip,127.0.0.1]
我什至尝试给0.0.0.0,但仍然没有运气。使用 localhost,我可以从我自己的机器连接,但如果我提到 M1 地址并在本地尝试使用该地址,我会得到
Cannot connect to Mongo DB at M1 address, network is unreachable.
我在这里卡了很久。刚开始使用mongodb,请原谅任何新手问题。
我所有的 mongo 服务都已启动并正在运行,并且能够使用终端或本地主机上的任何 mongo 客户端访问数据。
这是我在终端上运行命令mongod 时的日志:
2018-09-11T11:14:13.977+0530 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] MongoDB starting : pid=11307 port=27017 dbpath=/data/db 64-bit host=DELC02S5E2CG8WN.sea.corp.expecn.com
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] db version v4.0.2
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] git version: fc1573ba18aee42f97a3bb13b67af7d837826b47
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] allocator: system
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] modules: none
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] build environment:
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] distarch: x86_64
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] target_arch: x86_64
2018-09-11T11:14:13.993+0530 I CONTROL [initandlisten] options: {}
2018-09-11T11:14:13.993+0530 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-09-11T11:14:13.993+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7680M,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),
2018-09-11T11:14:14.698+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:698414][11307:0x7fff8fb43380], txn-recover: Main recovery loop: starting at 2/7040
2018-09-11T11:14:14.792+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:792304][11307:0x7fff8fb43380], txn-recover: Recovering log 2 through 3
2018-09-11T11:14:14.856+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:856010][11307:0x7fff8fb43380], txn-recover: Recovering log 3 through 3
2018-09-11T11:14:14.904+0530 I STORAGE [initandlisten] WiredTiger message [1536644654:904754][11307:0x7fff8fb43380], txn-recover: Set global recovery timestamp: 0
2018-09-11T11:14:15.037+0530 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten]
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten]
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-09-11T11:14:15.103+0530 I CONTROL [initandlisten]
2018-09-11T11:14:15.157+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-09-11T11:14:15.161+0530 I NETWORK [initandlisten] waiting for connections on port 27017
mongodb 版本是db version v4.0.2,我使用的是mac。
另外,当我绑定 M2 机器的 ip 并执行 mongo --host m2.address 时,我得到了这个:
mongo --host m2.address
MongoDB shell version v4.0.2
connecting to: mongodb://m2.address:27017/
2018-09-11T11:31:07.186+0530 E QUERY [js] Error: couldn't connect to server m2.address:27017, connection attempt failed: SocketException: Error connecting to m2.address:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
更新
这些是我在尝试连接之前执行的步骤:
- 启动
mongodb服务:brew services start mongodb - 通过运行命令
mongod启动mongod - 使用 Robo3T 通过指定
0.0.0.0作为连接地址来创建连接。也试过具体地址。 - 全部给出“网络无法访问”错误。
如果在启动时缺少任何参数或做错了什么,请告诉我。
【问题讨论】:
-
@AnthonyWinzlet 如果您提到的链接解决了我的问题,我真的不明白。请详细说明。
-
我能做到
brew services start mongodb猜猜它启用了吗? -
是的。它开始了。检查提到步骤的更新问题。
-
据我了解,如果您的
MongoDB设置在M1计算机(IP:192.168.1.1)中。您可以使用 M1(192.168.1.1) 的 IP 地址访问M2上的 MongoDB。 -
这是主要问题。它不适用于 M2。