如果主服务器宕机了如何连接到从服务器 -- 复制
我正在 MongoDb 中进行数据复制,目前有一个主节点和几个从节点。所有这些都在不同的端口上运行,但它们也可以在不同的机器上(我正在测试 atm)。
我的问题是,我将如何从我的代码连接到这些?目前,我只有一个 db 类的实例,它连接到本地主机上的 x 端口。显然,如果该节点发生故障,我想使用本地主机上 y 端口的从属节点,如果失败,则使用本地主机上 z 端口的从属节点。我应该为不同的连接使用单独的数据库对象吗?
I'm playing around with data replication in MongoDb, and I currently have a master and several slave nodes. All of these are running on different ports, but they could just as well be on different machines (I'm testing atm).
My question is, how would I go about connecting to these from my code? Currently, I just have one instance of a db class, which is connected to x port on localhost. Obviously, if this node fails, I want to use the slave at y port on localhost, and if that fails, z port on localhost. Shall I use separate db objects for different connections?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我查看了驱动程序源代码,看起来这是配置集群的方法:
Okay, I've looked through the driver source code, and it looks like this is the way to configure clusters: