Replication provides redundancy and increases data availability. With multiple copies of data on different database servers, replication protects a database from the loss of a single server. Replication also allows you to recover from hardware failure and service interruptions. With additional copies of the data, you can dedicate one to disaster recovery, reporting, or backup.
使用RS,主要为了实现读写分离、HA、容灾等目的
The primary accepts all write operations from clients. Replica set can have only one primary. Because only one member can accept write operations, replica sets provide strict consistency. To support replication, the primary logs all changes to its data sets in its oplog.
只有primary可写
An arbiter will always be an arbiter. A primary may step down and become a secondary. A secondary may become the primary during an election.
Most deployments, however, will keep three members that store data: A primary and two secondary members.
Only add an arbiter to sets with even numbers of members. If you add an arbiter to a set with an odd number of members, the set may suffer from tied elections.
只有当replica set有偶数个节点时,才添加仲裁节点;如果replica set有奇数个节点(比如1个primary,2个secondary),不要添加仲裁节点
Do not run an arbiter on systems that also host the primary or the secondary members of the replica set.
The standard replica set deployment for production system is a three-member replica set. These sets provide redundancy and fault tolerance. Avoid complexity when possible, but let your application requirements dictate the architecture.
Replica sets use elections to determine which set member will become primary. Elections occur after initiating a replica set, and also any time the primary becomes unavailable.
From the perspective of a client application, whether a MongoDB instance is running as a single server (i.e. “standalone”) or a replica set is transparent.
rs.initiate()
rs.conf()
rs.add()
rs.status()
by default, read from secondary server is not allowed. for example, if try "show collections", you will see the following information:
{ "$err" : "not master and slaveOk=false", "code" : 13435 }
to solve this problem, execute
rs.slaveOK()
first
尝试将primary停止,一台secondary自动升级为primary。重新启动原来的primary后,它会降级为secondary。通过这种方式,实现了failover。数据库确实是始终保持可用的,但是目前还不清楚为何对于app来说是透明的。因为毕竟每一个节点的IP都是不同的,如果app中写死了primary的ip地址,那么虽然有了新的primary,app也不知道应该将请求地址切换到新的primary上
猜测应该是在driver中提供了这个能力,即创建连接时指定的不是ip地址,而是replica set的name,由driver来决定primary的地址。明天需要写一个demo验证一下
分享到:
相关推荐
k8s 安装 MongoDB 分片(Sharding)+ 副本集(Replica Set) k8s 安装 MongoDB 分片(Sharding)+ 副本集(Replica Set)是结合 Kubernetes(k8s)和 MongoDB 实现高可用性和高性能的解决方案。本解决方案通过使用 ...
MongoDB的复制集(Replica Set)是一种高可用性架构,用于确保数据的冗余和容错性。在MongoDB中,复制集是由多个具有相同数据副本的节点组成,其中一个是主节点(Primary),其余是次级节点(Secondary)。主节点...
MongoDB的副本集(Replica Set)是一种高可用性解决方案,它通过在多个节点之间复制数据来确保数据的冗余和容错性。在MongoDB中,副本集由一组 MongoDB实例组成,包括一个主节点(Primary)和多个从节点...
信息 该文件描述了如何在 Docker 上运行 Mongo DB Replica Set。 我们假设主机上的 ...$ cd docker-mongodb-replicaset $ docker build -t mongo . 使用副本集启动 docker 容器 $ ./start.sh 使用 bash 再运行一个
在本文中,我们将探讨如何解决在尝试添加仲裁节点时遇到的 "replica set IDs do not match" 错误。 首先,让我们理解仲裁节点的角色。仲裁节点并不存储数据,但它们参与选举过程,帮助确定哪个节点应该是主节点。在...
MongoDB的Replica Set是一种高可用性和数据冗余的解决方案,它可以确保在多个服务器之间复制数据,从而提高系统的性能和容错能力。与Master-Slave模式不同,Replica Set可以自动实现故障转移和恢复,增加了系统的...
ansible-mongo-replicaset-role 前言 使用ansible搭建的一个精简版的mongo replicaset。安装的服务器centos7。 安装思路 1、通过rpm安装mongo的包,然后安装依赖的程序 2、配置mongo.service 3、配置mongo.conf,...
Centos7 安装Mongo replica set做读写分离.md 存放这里,让大家下载快捷一点
Linux运维-运维课程MP4频11-18-08-deployment和replicaset小结.mp4
MongoDB的复制集(Replica Set)是一种高可用性解决方案,它可以确保数据的冗余和在主节点故障时提供自动故障转移。复制集通常由多个成员组成,包括一个主节点(Primary)、一个或多个次级节点(Secondary)以及可选...
在大型分布式系统中,为了实现水平扩展和数据冗余,MongoDB提供了分片(Sharding)和复制集(Replica Set)的功能。本文将深入探讨如何使用这两种技术来设置MongoDB集群。 **一、MongoDB分片** 1. **分片概念**: ...
在具体的实现上,Deployment、ReplicaSet和Pod的关系是:Deployment控制器根据ReplicaSet对象的定义来管理Pod的创建、删除和更新,而ReplicaSet对象则根据Pod模板来创建、删除和更新Pod。 在Kubernetes项目中,...
【描述】:“17 经典PaaS的记忆:作业副本与水平扩展.pdf”讲述了在Kubernetes中如何进行作业副本管理和水平扩展,重点是Deployment和ReplicaSet的角色。 【标签】:“互联网” 【内容摘要】: 这篇文章主要探讨了...
- **编辑扩缩容**:直接编辑ReplicaSet配置文件中的`replicas`字段,然后使用`kubectl apply -f pc-replicaset.yaml`命令应用更改。 - **命令行扩缩容**:使用`kubectl scale rs pc-replicaset --replicas=2 -n dev`...
MongoDB的Replica Sets+Sharding架构是大数据时代下应对高可用性和可扩展性需求的重要解决方案。本篇文章将深入探讨这两个关键特性在Windows环境下的应用。 **副本集(Replica Sets)** MongoDB的副本集是一种高可用...