更新时间:2022-05-18 08:28:35
首先,要确保它不是防火墙问题,请在两台服务器上都停止IPTABLES(不要忘了以后重新启用).
Firstly, To ensure its not a firewall issue, stop IPTABLES on both servers (don't forget to re-enable afterwards).
在您要连接的计算机上,直接SSH到它并确保MongoDB在运行,在本地连接并检查您是否可以访问数据库.
On the machine that you are trying to connect to, ssh directly to it and ensure MongoDB is running, Connect locally and check that you can access a DB.
默认情况下,
MongoDb未配置为接受来自远程主机的连接,请确保您在/etc/mongodb.conf
文件中包含以下行:
MongoDb isn't configured to accept connections from remote hosts by default, could you ensure you have these lines in your /etc/mongodb.conf
file:
bind_ip = 0.0.0.0
port = 27017
确保在进行任何更改后重新启动MongoDB.尝试此操作,如果您仍然遇到问题,请发表评论,我会用更多建议来更新答案.
Make sure you restart MongoDB after making any changes. Try this and comment if your still having issues and I'll update the answer with more suggestions.
编辑:从2.6版开始,配置文件格式已更改为YAML,详细信息此处,文件应位于/etc/mongod.conf
.
As of version 2.6 the config file format has changed to YAML, details here, the file should be located at /etc/mongod.conf
.
net:
bindIp: 0.0.0.0
port: 27017