Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo can't connect to remote instance

Tags:

mongodb

I installed mongodb on remote server via vagrant. I can access postgres from my local system but mongo is not available. When I login via ssh and check mongo status it says that mongo running, I can make queries too. When I try to connect from my local system using this command:

mongo 192.168.192.168:27017

I get an error

MongoDB shell version: 2.6.5
connecting to: 192.168.192.168:27017/test
2014-12-27T22:19:19.417+0100 warning: Failed to connect to 192.168.192.168:27017, reason: errno:111 Connection refused
2014-12-27T22:19:19.418+0100 Error: couldn't connect to server 192.168.192.168:27017 (192.168.192.168), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed

looks like mongo not listen to connection from other ips? I commented bind_ip in mongo settings but it doesn't help.

services for 192.168.192.168 via nmap command:

PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
111/tcp  open  rpcbind
5432/tcp open  postgresql
9000/tcp open  cslistener

Looks like mongd listen

sudo lsof -iTCP -sTCP:LISTEN | grep mongo
mongod    1988     mongodb    6u  IPv4   5407      0t0  TCP *:27017 (LISTEN)
mongod    1988     mongodb    8u  IPv4   5411      0t0  TCP *:28017 (LISTEN)

Firewall rules

sudo iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination   

Update My mongo config

dbpath=/var/lib/mongodb

#where to log
logpath=/var/log/mongodb/mongodb.log

logappend=true

#bind_ip = 127.0.0.1
#port = 27017

# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true

# Enables periodic logging of CPU utilization and I/O wait
#cpu = true

# Turn on/off security.  Off is currently the default
#noauth = true
#auth = true
like image 819
strz Avatar asked Mar 18 '23 12:03

strz


1 Answers

Solution is to change mongo configuration bind_ip = 0.0.0.0

like image 59
strz Avatar answered Mar 20 '23 14:03

strz