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的备份集的检测,优化,部署
信息 该文件描述了如何在 Docker 上运行 Mongo DB Replica Set。 我们假设主机上的 ...$ cd docker-mongodb-replicaset $ docker build -t mongo . 使用副本集启动 docker 容器 $ ./start.sh 使用 bash 再运行一个
NULL 博文链接:https://tcrct.iteye.com/blog/2108099
ansible-mongo-replicaset-role 前言 使用ansible搭建的一个精简版的mongo replicaset。安装的服务器centos7。 安装思路 1、通过rpm安装mongo的包,然后安装依赖的程序 2、配置mongo.service 3、配置mongo.conf,...
Centos7 安装Mongo replica set做读写分离.md 存放这里,让大家下载快捷一点
主要给大家介绍了关于MongoDB添加仲裁节点报错:replica set IDs do not match的解决方法,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧
Linux运维-运维课程MP4频11-18-08-deployment和replicaset小结.mp4
mongodb的多服务器配置,以前写过一篇文章,是master-slave模式的,master-slave模式,不能自动实现故障转移和恢复。所以推荐大家使用mongodb的replica set,来实现多服务器的高性能。
mongo集群分片 使用分片和ReplicaSet设置集群MongoDB
replica set多服务器主从,添加,删除节点,肯定会经常遇到的。下面详细说明一下,添加,删除节点的2种方法。
Mongodb的Replica Sets + Sharding架构(window篇)
NULL 博文链接:https://star45.iteye.com/blog/2039957
mongodb的集群搭建方式主要有三种,主从模式,Replica set模式,sharding模式, 三种模式各有优劣,适用于不同的场合,属Replica set应用最为广泛,主从模式现在用的较少,sharding模式最为完备,但配置维护较为复杂 ...
Deployment控制ReplicaSet的版本属性,而ReplicaSet控制Pod的数量。这种设计模式实现了水平扩缩容和版本属性控制的更新/回滚。 水平扩缩容 水平扩缩容是Kubernetes中的一种基本操作,通过修改ReplicaSet控制的Pod...
Kubernetes的核心概念包括Pod、ReplicaSet、Deployment、Service等。Pod是Kubernetes中的最小单元,表示一个或多个容器的集合。ReplicaSet是一种确保Pod副本数量的控制器。Deployment是Kubernetes中的一种部署方式,...
1.2、ReplicaSet 名称: 副本控制器 作用:ReplicaSet 跟 ReplicationController 没有本质的不同,只是名字不一样,并且 ReplicaSet 支持集合式的 selector(标签选择器) 简称:RS Rs 和 RC 基本作用是一样的,都是...