MongoDB 具有外部地址的副本集

MongoDB Replica set with external addresses

这是我的问题。 Mongodb 在我的 debian 8 服务器上完美运行,但我想用外部地址做一个副本集...这是我的问题:
- 我有两个 VPS 在不同的网络
- 我按照互联网上的教程进行操作,但出现错误消息 "either all host names in a replica set configuration must be localhost"

这是我的 mongodb 配置的一部分:

net:
port: 27017
bindIp: 51.X.X.1, 167.X.X.4

我没有绑定任何本地主机地址。我能做什么 ?我是否需要做一些特别的事情才能让它发挥作用?

此致

错误消息表明您的副本集配置包含本地主机地址,如果您没有在任何地方明确指定本地主机,则可能由 rs.initiate() 中的默认配置添加。

您可以检查 rs.conf() to review the current replicate set configuration. Since you want to specify a public hostname I would include your desired config for rs.initiate() rather than relying on the defaults when you initiate the replica set. I'd also recommend following the tutorials in the MongoDB documentation 的输出是否适合您的服务器版本,因为第三方教程可能已过时或遗漏重要细节。

如果您想更正现有配置,可以复制 rs.conf() 报告的当前副本集配置,编辑主机名或 IP 地址,然后将更新后的配置文档传递给 rs.reconfig().

注意:在绑定到外部 IP 之前,请查看 MongoDB Security Checklist 并确保您已配置适当的安全措施,如访问控制、身份验证、网络加密 (TLS/SSL) 和防火墙规则。理想情况下,你会有一个 VPN/VPC 用于你的副本集成员之间的私人通信,而不是直接使用 public 网络。