Cannot connect to remote mongodb server

吃可爱长大的小学妹 提交于 2020-01-06 06:36:25

问题


I changed bindIp setting to

bindIp: 127.0.0.1, 0.0.0.0

in mongod.conf on my ubuntu server hosted on Linode and restarted mongod and status looks ok.

I opened mongodb port on ufw

sudo ufw status Status: active

To Action From -- ------ ---- 22/tcp ALLOW Anywhere 10000
ALLOW Anywhere Nginx Full
ALLOW Anywhere 3333
ALLOW Anywhere 27017
ALLOW Anywhere 22/tcp (v6)
ALLOW Anywhere (v6) 10000 (v6)
ALLOW Anywhere (v6) Nginx Full (v6)
ALLOW Anywhere (v6) 3333 (v6)
ALLOW Anywhere (v6) 27017 (v6)
ALLOW Anywhere (v6)

Connecting to it from my mac throws error:

mongo mongodb://admin:secret@ubuntuipaddress/fielddb?authSource=admin MongoDB shell version v3.6.2 connecting to: mongodb://ubuntuipaddress/fielddb?authSource=admin 2018-04-08T13:47:32.212 W NETWORK [thread1] Failed to connect to ubuntuipaddress:27017, in(checking socket for error after poll), reason: Connection refused 2018-04-08T13:47:32.214 E QUERY
[thread1] Error: couldn't connect to server ubuntuipaddress:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:251:13 @(connect):1:6 exception: connect failed

How to fix this issue?


回答1:


Disable your firewall and try to see if you can connect, if you can then it's your fw rules. Try this first to see if this helps.




回答2:


The problem was wrong setting of bindIP in mmongod.conf. Changing to:

bindIp: 127.0.0.1,ip_address_of_host_running_mondgod

fixed the problem. Replace ip_address_of_host_running_mondgod with ip address of host running mongod like 137.142.177.4



来源:https://stackoverflow.com/questions/49716190/cannot-connect-to-remote-mongodb-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!