开发环境 Laravel 链接 MongoDB 数据库时会报 No suitable servers found 的异常

开发环境

laravel  5.1.46
php  5.6
mongodb 3.4.0-rc2
php 的 mongodb 扩展是 mongodb1.2.9

我们的Mongodb 是安装在阿里云上的,阿里云上测试环境(内网连接)从来没出过这种异常,只有在本地开发环境(外网链接)的时候,尤其每天刚开始连的时候,就会出现如下提示:

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

是链接超时的异常,但是网速什么的都测过,没啥问题,而且用 robomongo 客户端连的时候,没有问题。
测试数据库没有做副本集,就是单库。
之前 Google 过,说是 ipv6引起的,根据提示修改之后,还是没解决该问题
mongodb 配置文件如下

# cat /etc/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: /data/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /data/mongodb/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

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.
  ipv6: false

security:
  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

请问下有没有遇到过类似问题的

《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 3
Summer

robomongo 使用的是『直接连接』还是『SSL』或者『SSH』连接?

file

bindIp: 0.0.0.0  # Listen to local interface only, comment to listen on all interfaces.

? 你这里绑定了只允许本地连接,如果要打开,注释掉即可,不过请注意安全,最好开启下认证。

6年前 评论

@Summer robomongod 使用的是直接连接。然后 bindIp 这里,我感觉他这个有点不靠谱,照着他这个说明,只有本地能访问的话,我本地开发环境就应该一直连不上才对,现在的情况是,我本地大多数能连上,每天刚开始连的时候会连不上。
我现在先把 bindIp 这行注释掉,试试看再说吧。
认证一开始就是开启的。

6年前 评论

bug主 解决这个问题了吗?

4年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!