Mongo DB - 独立版和独立版之间的区别1-node 副本集 [英] Mongo DB - difference between standalone & 1-node replica set

查看:72
本文介绍了Mongo DB - 独立版和独立版之间的区别1-node 副本集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Mongo DB 事务,最近我了解到事务不适用于 Mongo 独立模式,但仅适用于副本集(Mongo DB with C# - 文档已添加与交易无关).
另外,我了解到不建议将独立模式用于生产.

I needed to use Mongo DB transactions, and recently I understood that transactions don't work for Mongo standalone mode, but only for replica sets (Mongo DB with C# - document added regardless of transaction).
Also, I read that standalone mode is not recommended for production.

所以我发现只需在 mongod.cfg 中定义一个副本集名称就足以将 Mongo DB 作为副本集而不是独立运行.
更改后,Mongo 事务开始工作.
然而,虽然我并没有真正使用复制功能,但将其用作副本集感觉有点奇怪,而且我想确保我使用的是有效的配置.

So I found out that simply defining a replica set name in the mongod.cfg is enough to run Mongo DB as a replica set instead of standalone.
After changing that, Mongo transactions started working.
However, it feels a bit strange using it as replica-set although I'm not really using the replication functionality, and I want to make sure I'm using a valid configuration.

所以我的问题是:

  1. 假设我真的不需要复制、负载平衡或任何其他可扩展功能,将 Mongo 作为 1 节点副本集运行是否有任何问题/缺点?(据说我需要它来允许交易)
  2. 作为独立运行与作为 1 节点副本集运行之间有哪些功能和性能差异(如果有)?
  3. 我了解到不建议将独立模式用于生产,尽管这听起来像是最基本的配置.我知道这个配置在大多数情况下不使用,但有时您可能希望将其用作本地机器上的标准数据库.那么为什么不推荐独立模式呢?是不够稳定,还是其他原因?

推荐答案

假设我真的不需要复制、负载平衡或任何其他可扩展功能,将 Mongo 作为 1 节点副本集运行是否有任何问题/缺点?

Is there any problem/disadvantage with running Mongo as a 1-node replica set, assuming I don't really need the replication, load balancing or any other scalable functionality?

您没有合适的副本集提供的高可用性.因此,不建议将其用于生产部署.不过这对开发来说很好.

You don't have high availability afforded by a proper replica set. Thus it's not recommended for a production deployment. This is fine for development though.

请注意,副本集的功能主要是关于高可用性而不是扩展.

Note that a replica set's function is primarily about high availability instead of scaling.

独立运行与作为 1 节点副本集运行之间的功能和性能差异(如果有)是什么?

What are the functionality and performance differences, if any, between running as standalone vs. running as a 1-node replica set?

单节点副本集将具有 oplog.这意味着您将使用更多磁盘空间来存储 oplog,并且任何插入/更新操作也会写入 oplog(写放大).

A single-node replica set would have the oplog. This means that you'll use more disk space to store the oplog, and also any insert/update operation would be written to the oplog as well (write amplification).

那么为什么不推荐独立模式?是不够稳定,还是其他原因?

So why is standalone mode not recommended? Is it not stable enough, or other reasons?

生产中的 MongoDB 在设计时考虑了副本集部署,用于:

MongoDB in production was designed with a replica set deployment in mind, for:

  • 面对节点故障时的高可用性
  • 滚动维护/升级,无需停机
  • 可以横向扩展读取
  • 可以在不属于高可用性节点的特殊用途节点中拥有数据副本

简而言之,MongoDB 被设计为一个容错的分布式数据库(水平扩展),而不是典型的 SQL 单体数据库(垂直扩展).这个想法是,如果您丢失副本集的一个节点,其他节点将立即接管.大多数时候,您的应用程序甚至不知道数据库端出现故障.相比之下,单体数据库服务器的故障会立即中断您的应用程序.

In short, MongoDB was designed to be a fault-tolerant distributed database (scales horizontally) instead of the typical SQL monolithic database (scales vertically). The idea is, if you lose one node of your replica set, the others will immediately take over. Most of the time your application don't even know there's a failure in the database side. In contrast, a failure in a monolithic database server would immediately disrupt your application.

这篇关于Mongo DB - 独立版和独立版之间的区别1-node 副本集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆