无法连接到远程计算机上运行的 mongodb
我有 mongodb 在远程服务器上运行。我可以 ssh 到远程服务器并从远程计算机上的 shell 连接到 mongodb。但是我必须从我的 python 脚本连接到该 mongodb 实例。 但是,我无法使用以下命令从运行 linux 的本地计算机上的 shell 直接连接到 mongodb:
mongo <remote_ip>:27017
或通过 pymongo 使用
connection = pymongo.Connection("<remote_ip>", 27017)
使用 pymongo 时出现以下错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pymongo-1.11-py2.6-linux-i686.egg/pymongo/connection.py", line 370, in __init__
self.__find_master()
File "/usr/local/lib/python2.6/dist-packages/pymongo-1.11-py2.6-linux-i686.egg/pymongo/connection.py", line 605, in __find_master
raise AutoReconnect("could not find master/primary")
AutoReconnect: could not find master/primary
可能是什么原因导致此问题?这是否意味着 mongo 正在 27017 以外的端口上运行,如果是这样,我如何找出它正在哪个端口上运行?
请帮忙 谢谢
I have mongodb running on a remote server. I can ssh to the remote server and connect to mongodb from the shell on the remote machine. However i have to connect to that mongodb instance from my python script.
However, im unable to connect to mongodb directly from the shell on my local machine running linux using the command:
mongo <remote_ip>:27017
or through pymongo using
connection = pymongo.Connection("<remote_ip>", 27017)
I get the below error when using pymongo:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pymongo-1.11-py2.6-linux-i686.egg/pymongo/connection.py", line 370, in __init__
self.__find_master()
File "/usr/local/lib/python2.6/dist-packages/pymongo-1.11-py2.6-linux-i686.egg/pymongo/connection.py", line 605, in __find_master
raise AutoReconnect("could not find master/primary")
AutoReconnect: could not find master/primary
What could be causing this problem ?. Does it mean mongo is running on a port other than 27017 and if so how can i find out which port it is running on ?
Please Help
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在运行 mongodb 的计算机上使用
netstat -a -p
来查看它连接到哪个端口。 (netstat -a
列出所有连接,-p
提供拥有该连接的程序的名称。)还要确保远程计算机允许该端口上的外部连接(连接没有被防火墙阻止)并且 mongodb 正在接受远程连接。You can use
netstat -a -p
on the machine running mongodb to see what port it's attached to. (netstat -a
lists all connections and-p
provides the name of the program owning the connection.) Also make sure the remote computer is allowing external connections on that port (the connections aren't being blocked by a firewall) and that mongodb is accepting remote connections.