本文介绍了无法使用公共IP地址连接到MongoDB副本集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在MongoDB中配置了一个三节点副本集;复制是同步的.

I have configured a three-node replica set in MongoDB; replication is in sync.

我能够分别连接到每台服务器,并使用每台服务器的专用IP地址可以连接到副本集,如下所示:

I am able to connect to each server individually, and using each server's private IP address I can to connect to the replica set like this:

但是当我尝试使用服务器的公共IP地址连接到副本集时,如下所示:

But when I try to connect to the replica set using the servers' public IP addresses, like this:

我收到错误消息:"未检测到rs0的主要对象".

I get an error: "No primary detected for set rs0".

推荐答案

当连接到副本集时,应使用相同的地址(ip地址或主机名)作为节点用于副本集配置中互相访问.对于副本集部署,您需要:

When you connect to the replica set, you should use the same addresses (ip addresses or host names) as the nodes use for each other in the replica set configuration. For replica set deployment, you need to:

实际上,最好不要使用公共ip地址配置副本集.使用私有IP地址更加安全,这有助于确保您的数据库只能接收来自授权位置的连接.

In practice, it is best not to configure your replica set using public ip addresses; it is more secure to use the private ip addresses, which helps ensure that your database can only receive connections from authorised locations.

这篇关于无法使用公共IP地址连接到MongoDB副本集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:59