无法通过 php 连接到远程主机上的 MongoDB
我有这样的网络配置(请参阅链接 - http://s58.radikal.ru/ i160/1110/4c/1c2c5d74edd0.jpg)
其中: Notebook - 包含 Zend (Windows) 上 mongodb+web 项目的 Apache+php+mongodb+php 驱动
路由器 - 虚拟站(192.168.5.23 接口上的 nat + ipfw)
natd .conf:
interface le0
same_ports
use_sockets
redirect_port tcp 192.168.5.23:27017 27017
redirect_port tcp 192.168.5.23:27017 27017
ipfw: 允许从任何虚拟站到任何
虚拟站 2 - 仅包含 mongodb(无 php、apache 或 mongodb php 驱动程序)
1 - 从笔记本 ping 到 mongodb 主机并向后 - 有效。
2 - 虚拟 mongodb 主机上的 shell:mongo 192.168.5.20:27017 - 成功连接到笔记本的 mongodb
3 - 尝试从笔记本连接到虚拟主机导致此类错误:
C:\mongodb1.8.2\bin>mongo 192.168.9.21:27017
MongoDB shell version: 1.8.2
connecting to: 192.168.9.21:27017/test
Sun Oct 02 22:31:14 Error: couldn't connect to server 192.168.9.21:27017 shell/mongo.js:81
exception: connect failed
4 - 尝试在 php 项目(www.vm)中使用带有数据库的远程主机.lcl):
an exception occured while bootstrapping
connecting to vm-db1.lcl failed: Unknown error
Stack Trace:
#0 C:\www\vm-db1.lcl\library\Zirrk\Database\MongoConnection.php(16): Mongo->__construct('vm-db1.lcl')
请给我建议——我应该朝什么方向寻找我的错误! 非常感谢!
I have such network configuration (see link - http://s58.radikal.ru/i160/1110/4c/1c2c5d74edd0.jpg)
Where:
Notebook - contain Apache+php+mongodb+php drivers for mongodb+web project on Zend (Windows)
router - virtual station (nat on 192.168.5.23 interface + ipfw)
natd.conf:
interface le0
same_ports
use_sockets
redirect_port tcp 192.168.5.23:27017 27017
redirect_port tcp 192.168.5.23:27017 27017
ipfw:
allow from any to any
virtual station 2 - contain ONLY mongodb (no php, apache, or mongodb php drivers )
1 - ping from notebook to mongodb host and backward - works.
2 - shell on virtual mongodb host: mongo 192.168.5.20:27017 - connected to notebook's mongodb successfully
3 - attempt to connect from notebook to virtual host cause such error:
C:\mongodb1.8.2\bin>mongo 192.168.9.21:27017
MongoDB shell version: 1.8.2
connecting to: 192.168.9.21:27017/test
Sun Oct 02 22:31:14 Error: couldn't connect to server 192.168.9.21:27017 shell/mongo.js:81
exception: connect failed
4 - attempt to use remote host with DB in php project (www.vm.lcl):
an exception occured while bootstrapping
connecting to vm-db1.lcl failed: Unknown error
Stack Trace:
#0 C:\www\vm-db1.lcl\library\Zirrk\Database\MongoConnection.php(16): Mongo->__construct('vm-db1.lcl')
Please, give me advise - in what direction should I search my mistakes!
Thank a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过将 natd.conf 中的规则更改
为
redirect_port tcp 192.168.5.23:27017 192.168.9.21:27017
在了解如何修复它之前,我已经使用 apache+php+mongo-php- 在虚拟网络 (192.168.9.0/24) Web 服务器 (192.168.9.11) 中创建驱动程序(mongodb - 未安装),并尝试连接到 192.168.9.21
这是没有意义的。我花了一整天的时间进行头脑风暴和谷歌搜索信息,但仍然一无所获。 (连接到服务器时超时错误)。然后我休息了几个小时,明白了,在我的例子中,所有流量都经过 Freebsd-gateway 主机并添加到 natd.conf
重新启动网关服务器,然后它就开始工作了!
I've solve this problem by changing rule in natd.conf
to
redirect_port tcp 192.168.5.23:27017 192.168.9.21:27017
Before understanding how to fix it, I've create in virtual network (192.168.9.0/24) web-server (192.168.9.11) with apache+php+mongo-php-driver (mongodb - was not installed), and tried to connect to 192.168.9.21
This was no sense. I've spent whole day in brainstorm and googling information, but still nothing. (Error was in timeout while connection to server). Then I rest for few hours, and understand, that in my case, all traffic goes through Freebsd-gateway host and add to natd.conf
reboot gate-way server, and it come to work!