douba7784
2018-01-29 17:33
浏览 90

无法从家园连接主机mongodb

I have a laravel 5.2 project on homestead 7 which works with mysql and mongodb, I have configured it to connect to host (my mac AMPPS) mysql and mongodb servers.

mysql is connected successfully but I can't connect to host mongodb from homestead.

when I try to connect to host mongodb server from homestead using mongo command I get below error :

vagrant@homestead:~$ mongo 192.168.10.1:27017/admin
MongoDB shell version: 3.2.18
connecting to: 192.168.10.1:27017/admin
2018-01-29T13:18:36.967+0000 W NETWORK  [thread1] Failed to connect to 192.168.10.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2018-01-29T13:18:36.968+0000 E QUERY    [thread1] Error: couldn't connect to server 192.168.10.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:231:14
@(connect):1:6

exception: connect failed

as you can see my host ip address is 192.168.10.1 and homestead ip address is 192.168.10.10.

And whenever I try to connect to mongodb from laravel mongodb driver I get below error message :

ConnectionTimeoutException in Collection.php line 174:
No suitable servers found (`serverSelectionTryOnce` set): [connection refused calling ismaster on '192.168.10.1:27017']

FYI : I used This shell script to install mongodb and it's driver on homestead 7 with php 7.1

Any suggestion how to fix this ?

图片转代码服务由CSDN问答提供 功能建议

我在Homestead 7上有一个laravel 5.2项目,它与mysql和mongodb一起使用,我已将其配置为连接到主机 (我的mac AMPPS)mysql和mongodb服务器。

mysql连接成功但我无法连接到宅基地的主机mongodb。

当我 尝试使用mongo命令从宅基地连接到主机mongodb服务器我得到以下错误:

  vagrant @ homestead:〜$ mongo 192.168.10.1:27017/admin
MongoDB shell version:  3.2.18 
连接到:192.168.10.1:27017/admin
2018-01-29T13:18:36.967+0000 W NETWORK [thread1]无法连接到192.168.10.1:27017,in(在轮询后检查套接字是否有错误)  ,原因:错误:111连接被拒绝
2018-01-29T13:18:36.968 + 0000 E QUERY [thread1]错误:无法连接到服务器192.168.10.1:27017,连接尝试失败:
connect @src / mongo /  shell / mongo.js:231:14 
 @(connect):1:6 
 
exception:连接失败
   
 
 

因为你可以看到我的主机ip 地址 ess是 192.168.10.1 ,宅基地址是 192.168.10.10

每当我尝试从laravel mongodb连接到mongodb 驱动程序我得到以下错误消息:

  Collection.php第174行中的ConnectionTimeoutException:
找不到合适的服务器(`serverSelectionTryOnce` set):[连接拒绝在'192.168上调用ismaster。  10.1:27017'] 
   
 
 

仅供参考我使用这个 shell脚本用于安装mongodb及其驱动程序在hometead 7上使用php 7.1

有任何建议如何解决这个问题?< / p>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpepbjp126917 2018-01-30 09:46
    已采纳

    The solution to this problem was to edit host /etc/mongodb.conf and set bind-ip to 0.0.0.0

    bind_ip = 0.0.0.0
    

    remember to restart mongodb server, then I connected to the host mongodb server.

    点赞 打赏 评论

相关推荐 更多相似问题