开发者

Can't connect to MongoDB on remote host via php

开发者 https://www.devze.com 2023-04-10 07:36 出处:网络
I have such network configuration (see link - http://s58.radikal.ru/i160/1110/4c/1c2c5d74edd0.jpg) Where:

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!


I've solve this problem by changing rule in natd.conf

redirect_port tcp 192.168.5.23:27017 27017

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

$m = new Mongo("mongodb://192.168.9.21:27017");

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

redirect_port tcp 192.168.9.11:27017 192.168.9.21:27017

reboot gate-way server, and it come to work!

0

精彩评论

暂无评论...
验证码 换一张
取 消