开发环境 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:
请问下有没有遇到过类似问题的
推荐文章: