无法连接到远程mongodb服务器 [英] Cannot connect to remote mongodb server
问题描述
我将bindIp设置更改为
I changed bindIp setting to
bindIp:127.0.0.1,0.0.0.0
bindIp: 127.0.0.1, 0.0.0.0
在Linode上托管的ubuntu服务器上的mongod.conf中,重新启动了mongod,状态看起来还可以.
in mongod.conf on my ubuntu server hosted on Linode and restarted mongod and status looks ok.
我在ufw上打开了mongodb端口
I opened mongodb port on ufw
sudo ufw状态 状态:有效
sudo ufw status Status: active
从采取行动 ------- ---- 22/tcp允许在任何地方10000
随时随地Nginx Full
随处可见3333
随时随地27017
随时随地22/tcp(v6)
允许任何地方(v6)10000(v6)
允许任何地方(v6)Nginx Full(v6)
允许任何地方(v6)3333(v6)
允许在任何地方(v6)27017(v6)
允许在任何地方(v6)
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)
从我的Mac连接到它会引发错误:
Connecting to it from my mac throws error:
mongo mongodb://admin:secret @ ubuntuipaddress/fielddb?authSource = admin MongoDB Shell版本v3.6.2连接到: mongodb://ubuntuipaddress/fielddb?authSource = admin 2018-04-08T13:47:32.212 W网络[thread1]无法连接到 ubuntuipaddress:27017,in(轮询后检查套接字是否有错误), 原因:连接被拒绝2018-04-08T13:47:32.214 E QUERY
[thread1]错误:无法连接到服务器ubuntuipaddress:27017, 连接尝试失败:connect@src/mongo/shell/mongo.js:251:13 @(connect):1:6例外:连接失败
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
如何解决此问题?
推荐答案
问题是mmongod.conf中的bindIP设置错误.更改为:
The problem was wrong setting of bindIP in mmongod.conf. Changing to:
bindIp:127.0.0.1,ip_address_of_host_running_mondgod
bindIp: 127.0.0.1,ip_address_of_host_running_mondgod
解决了该问题.替换ip_address_of_host_running_mondgod 与运行mongod的主机的ip地址类似137.142.177.4
fixed the problem. Replace ip_address_of_host_running_mondgod with ip address of host running mongod like 137.142.177.4
这篇关于无法连接到远程mongodb服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!