什么是 MongoDB 中的集群?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43445975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a cluster in MongoDB?
提问by Ong Kong Tat
I am someone new to mongoDB and has absolutely no knowledge regarding databases so would like to know what is a cluster in MongoDB and what is the point of connecting to one in MongoDB? Is it a must to connect to one or can we just connect to the localhost?
我是 mongoDB 的新手,完全不了解数据库,所以想知道什么是 MongoDB 中的集群以及连接到 MongoDB 中的集群有什么意义?是必须连接到一个还是我们可以连接到本地主机?
回答by Julien TASSIN
A mongodb cluster is the word usually used for sharded clusterin mongodb. The main purposes of a sharded mongodb are:
甲mongodb的簇是通常用于字分片集群中的mongodb。分片 mongodb 的主要目的是:
- Scale reads and writes along several nodes
- Each node does not handle the whole data so you can separate data along all the nodes of the shard. Each node is a member of a shard (which is a replicaset, see below for the explanation) and the data are separated on all shards.
- 沿多个节点扩展读取和写入
- 每个节点不处理整个数据,因此您可以沿分片的所有节点分离数据。每个节点都是一个分片(它是一个副本集,解释见下文)的成员,并且数据在所有分片上是分开的。
This is the representation of a mongodb sharded cluster from the official doc.
这是来自官方文档的 mongodb 分片集群的表示。
If you are starting with mongodb, I do not recommend you to shard your data. Shards are way more complicated to maintain and handle than replicasets are. You should have a look at a basic replicaset. It is fault tolerant and sufficient for simple needs.
如果您开始使用 mongodb,我不建议您对数据进行分片。与副本集相比,分片的维护和处理要复杂得多。你应该看看一个基本的副本集。它是容错的,足以满足简单的需求。
The ideas of a replicaset are :
复制集的想法是:
- Every data are repartited on each node
- Only one node accept writes
- 每个数据都在每个节点上重新分区
- 只有一个节点接受写入
A replicaset representation from the official doc
来自官方文档的副本集表示
For simple apps there is no problem to have your mongodb cluster on the same host than your application. You can even have them on a single member replicaset but you won't be fault tolerant anymore.
对于简单的应用程序,将 mongodb 集群放在与应用程序相同的主机上是没有问题的。您甚至可以将它们放在单个成员副本集上,但您将不再具有容错能力。
回答by NattyC
Atlas-managed MongoDB deployments, or “clusters”, can be either a replica setor a sharded cluster.
replica set: A cluster of MongoDB servers that implements replication and automated failover. (Failover is a method of protecting computer systems from failure, in which standby equipment automatically takes over when the main system fails.)
– replication: A feature allowing multiple database servers to share the same data, thereby ensuring redundancy and facilitating load balancing. (Redundancy is a system design in which a component is duplicated so if it fails there will be a backup.)
sharded cluster: The set of nodes comprising a sharded MongoDB deployment. A sharded cluster consists of config servers, shards, and one or more mongos routing processes.
– sharding: A method for distributing data across multiple machines.
A sharded cluster consists of ten servers: one server for the mongos [interface between the client applications and the sharded cluster] and three servers each for the first replica set, the second replica set, and the config server replica set
– shard: A single mongod instance or replica set that stores some portion of a sharded cluster's total data set. In production, all shards should be replica sets.
Atlas 管理的 MongoDB 部署或“集群”可以是 副本集或分片集群。
副本集:实现复制和自动故障转移的 MongoDB 服务器集群。(故障转移是一种保护计算机系统免受故障影响的方法,当主系统出现故障时,备用设备会自动接管。)
–复制:允许多个数据库服务器共享相同数据的功能,从而确保冗余并促进负载平衡。(冗余是一种系统设计,其中组件被复制,因此如果出现故障,则会有备份。)
分片集群:包含分片 MongoDB 部署的节点集。分片集群由配置服务器、分片和一个或多个 mongos 路由进程组成。
–分片:一种跨多台机器分发数据的方法。
分片集群由 10 个服务器组成:一个服务器用于 mongos [客户端应用程序和分片集群之间的接口],三个服务器分别用于第一个副本集、第二个副本集和配置服务器副本集
– shard:单个 mongod 实例或副本集,用于存储分片集群总数据集的一部分。在生产中,所有分片都应该是副本集。
Sources: MongoDB docs: Glossary, Create a Cluster, Convert a Replica Set to a Sharded Cluster
来源:MongoDB 文档:词汇表、创建集群、将副本集转换为分片集群
回答by nitin.k
It will be more clear, if you create a cluster in the cloud websiteof mongo. Try free version. You can see live monitoring of servers.
如果在mongo的云网站上创建集群就更清楚了。试用免费版。您可以看到服务器的实时监控。