折腾:
【未解决】Win中尝试用Robot 3T连接和操作VMWare中macOS中MongoDB
期间,在Win中用Robot 3T连接VMWare中macOS中MongoDB,结果报错:
Cannot connect to the MongoDB at 192.168.17.128:27017. Network is unreachable. Reason: couldn't connect to server 192.168.17.128:27017, connection attempt failed: SocketException: Error connecting to 192.168.17.128:27017 :: caused by :: ����Ŀ�������������ܾ��������ӡ�
先去ping试试
C:\Users\xxx>ping 192.168.17.128 正在 Ping 192.168.17.128 具有 32 字节的数据: 来自 192.168.17.128 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.17.128 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.17.128 的回复: 字节=32 时间<1ms TTL=64
可以ping通的
或许是缺少权限认证?
好像也不是
然后上述错误中,错误原因是乱码,看不出原因
去试了试Test
到时能看出原因
No chance to load list of databases
点击 show error details
结果是前面的弹框
还是不知道根本原因错在哪里
是连不上IP 还是连不上内部的MongoDB ,还是缺少权限啥的
去试试win中cmd命令行
C:\Users\xxx>mongo --host 192.168.17.128 --port 27017 MongoDB shell version v4.0.10 connecting to: mongodb://192.168.17.128:27017/?gssapiServiceName=mongodb 2020-06-28T15:51:23.525+0800 E QUERY [js] Error: couldn't connect to server 192.168.17.128:27017, connection attempt failed: SocketException: Error connecting to 192.168.17.128:27017 :: caused by :: ����Ŀ�����������ܾ��������ӡ� : connect@src/mongo/shell/mongo.js:344:17 @(connect):2:6 exception: connect failed
现象依旧
错误是乱码的原因,或许是编码问题?
去设置为其他编码?
macOS内部试试
crifanli@crifanlideMac / mongo --host 192.168.17.128 --port 27017 MongoDB shell version v4.2.8 connecting to: mongodb://192.168.17.128:27017/?compressors=disabled&gssapiServiceName=mongodb 2020-06-28T00:55:11.336-0700 E QUERY [js] Error: couldn't connect to server 192.168.17.128:27017, connection attempt failed: SocketException: Error connecting to 192.168.17.128:27017 :: caused by :: Connection refused : connect@src/mongo/shell/mongo.js:341:17 @(connect):2:6 2020-06-28T00:55:11.339-0700 F - [main] exception: connect failed 2020-06-28T00:55:11.339-0700 E - [main] exiting with code 1
然后很明显是这个IP 貌似无法直接访问到MongoDB
✘ crifanli@crifanlideMac / ifconfig | grep 192.168 inet 192.168.17.128 netmask 0xffffff00 broadcast 192.168.17.255
而IP确定没错
所以:
估计是默认MongoDB没开对外权限,对外的IP地址?
所以去找找MongoDB的配置
mongo Network is unreachable Reason couldn’t connect to server connection attempt failed SocketException
解决robomongo连接报错Cannot connect to the MongoDB at localhost:27017.Network is unreachable_水越帆的博客-CSDN博客_network is unreachable. reason: couldnt connect t
Just change your bind_ip in /etc/mongod.conf from 127.0.0.1 to 0.0.0.0 then restart the service, and it works for me~
看来默认绑定到本机,不对外,所以要去改为:0.0.0.0,外部才能访问
crifanli@crifanlideMac / ll /etc/mongo ✘ crifanli@crifanlideMac /
此处配置文件不在/etc下面的
所以重新去找
找到之前的
mongod --config /usr/local/etc/mongod.conf
所以去找
/usr/local/etc/mongod.conf
去改为:
crifanli@crifanlideMac / cat /usr/local/etc/mongod.conf systemLog: destination: file path: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /usr/local/var/mongodb net: bindIp: 127.0.0.1 crifanli@crifanlideMac / vi /usr/local/etc/mongod.conf crifanli@crifanlideMac / cat /usr/local/etc/mongod.conf systemLog: destination: file path: /usr/local/var/log/mongodb/mongo.log logAppend: true storage: dbPath: /usr/local/var/mongodb net: # bindIp: 127.0.0.1 bindIp: 0.0.0.0
再去重启MongoDB:
crifanli@crifanlideMac / brew services restart mongodb-community Stopping `mongodb-community`... (might take a while) ==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community) ==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
再去试试
test即可成功连接。
【总结】
win中,用Robot 3T去访问,VMWare中macOS中安装的MongoDB,报错:
Cannot connect to the MongoDB at 192.168.17.128:27017. Network is unreachable. Reason: couldn't connect to server 192.168.17.128:27017, connection attempt failed: SocketException: Error connecting to 192.168.17.128:27017 :: caused by :: ����Ŀ�������������ܾ��������ӡ�
原因:
macOS中MongoDB默认只允许本机访问,所以外部无法访问而报错。
解决办法:给外部开放访问权限。
步骤:
把
mongodb的配置文件。
不过此处是:
/usr/local/etc/mongod.conf
中的:
net: bindIp: 127.0.0.1
改为:
net: bindIp: 0.0.0.0
再去重启mongodb,此处是:
brew services restart mongodb-community
即可。
注:
(1)关于MongoDB的配置文件:
一般都是:
/etc/mongod.conf
此处是通过之前安装MongoDB
【未解决】给Win中VMWare中macOS安装MongoDB和恢复MongoDB数据
期间的log:
To have launchd start mongodb/brew/mongodb-community now and restart at login: brew services start mongodb/brew/mongodb-community Or, if you don't want/need a background service you can just run: mongod --config /usr/local/etc/mongod.conf
而得知此处的配置文件是:
/usr/local/etc/mongod.conf
另外,如果找不到,且当前mongodb(服务端mongod)正在运行,则可以通过查看进程详情中可以看到conf配置文件路径。
比如:
crifanli@crifanlideMac / ps aux | grep mongod crifanli 8712 0.0 0.0 4258648 208 s000 R+ 1:10上午 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox mongod crifanli 8676 0.0 1.3 5524376 40376 ?? S 1:05上午 0:01.89 /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf
中已可以找到:
/usr/local/etc/mongod.conf
转载请注明:在路上 » 【已解决】Win中Robot 3T访问VMWare中macOS中MongoDB报错:Network is unreachable Reason couldn’t connect to server connection attempt failed SocketException