开发环境 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:

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

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 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年前 评论

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