Configure MongoDB Replica Set
Table of Contents
Introduction
A replica set provides MongoDB with redundancy and increased data availability by replicating the database to multiple servers. The primary member of the replica set can be used for read and write operations whereas the secondary members are available for read-only operations.
A replica set must consist of an odd number of MongoDB servers. If a single server fails, the replica set members must be able elect a new primary server. An election majority can also be achieved with two database servers by including a third MongoDB arbiter. The arbiter does not have to maintain a copy of the database, but it does need to be a separate server instance.
Requirements
- Minimum of three server instances
- MongoDB 2.6 installed and running
- Each server instance must allow TCP traffic from each replica set member over port 27017
- Each server instance hostname must be resolvable from each replica set member
As mentioned in the above requirements, each replica set member must be able to communicate with the other replica set members by their hostname. The hostname will default to the fully qualified domain name of each server. The server hostnames can be added to DNS, but the recommended method is to add all replica set member hostnames to their /etc/hosts file. For example:
10.10.200.1 mongodb01.yourdomain.com mongodb01
10.10.200.2 mongodb02.yourdomain.com mongodb02
10.10.200.3 mongodb03.yourdomain.com mongodb03
Create Replica Set
MongoDB must successfully be running on the primary server instance. The standalone instance of MongoDB can become a replica set member by assigning a replica set name in the MongoDB configuration file. To create a replica set called "rs0", add the following line to /etc/mongod.conf.
replSet=rs0
MongoDB will need to be restarted for the change to take affect.
sudo /etc/init.d/mongod restart
Use the mongo shell to connect once the service is running again.
mongo
Initiate the replica set from within the mongo shell.
rs.initiate()
The initial replica set configuration can be verified using rs.conf().
rs.conf()
{
"_id" : "rs0",
"version" : 1,
"members" : [
{
"_id" : 0,
"host" : "mongodb01.yourdomain.com:27017"
}
]
}
At this stage, the mongo shell prompt should also indicate the replica name and replica member role. For example:
rs0:PRIMARY>
The replica set is now created but more members must be added to achieve redundancy and increased data availability.
Add Secondary Members
The secondary MongoDB server instances must be successfully running MongoDB and accessible by the other members. The configuration file on the secondary members must reflect the same replica set name as the primary member. Add the following line to the /etc/mongod.conf on all secondary members.
replSet=rs0
Restart the MongoDB service.
sudo /etc/init.d/mongod restart
The secondary members can now be added from the mongo shell on the primary server using rs.add().
rs0:PRIMARY> rs.add("mongodb02.yourdomain.com")
rs0:PRIMARY> rs.add("mongodb03.yourdomain.com")
The rs.status() command can be used to verify the status of the replica set:
rs.status()
Add an Arbiter
An arbiter is an optional member of a replica set which stores no data. Instead, it is available to break election ties in a situation where there is an even number of MongoDB members.
An arbiter member does not require the same performance capabilities of a full MongoDB server, but it must reside on a separate server instance. Never configure an arbiter on an existing replica set member.
To add an arbiter, first install MongoDB on a server instance accessible by the other replica set members and add the replica set name to /etc/mongod.conf.
replSet=rs0
Unnecessary data can be reduced on the arbiter server by adding the following files to /etc/mongod.conf.
journal.enabled=false
smallFiles=true
preallocDataFiles=false
Now log into the primary replica set member and launch the mongo shell.
mongo
The arbiter can be added with the following command:
rs.addArb("arbiter01.yourdomain.com:27017")
原文地址:https://devops.profitbricks.com/tutorials/configure-mongodb-replica-set/#create-replica-set
Configure MongoDB Replica Set的更多相关文章
- 关于MongoDb Replica Set的故障转移集群——实战篇
如果你还不了解Replica Set的相关理论,请猛戳传送门阅读笔者的上一篇博文. 因为Replica Set已经属于MongoDb的进阶应用,下文中关于MongoDb的基础知识笔者就不再赘述了,请参 ...
- MongoDb Replica Set中使用的地址
Unable to connect to a member of the replica set matching the read preference Primary 今天尝试使用MongoDB ...
- MongoDB 学习笔记(三) MongoDB (replica set) 集群配置
MongoDB Replica Sets的结构类似于以集群,完全可以把他当成一个集群,因为他确实与集群实现的作用是一样的:如果其中一个节点出现故障,其他的节点会马上将业务接管过来.而无需停机操作 Mo ...
- mongodb replica set 和 nodejs中使用mongoose连接replica
一.mongodb replication 介绍 官网上的第一句话就是Replication is the process of synchronizing data across multiple ...
- MongoDB Replica Set搭建集群
MongoDB做集群,版本3.2官网推荐的集群方式Replica Set 准备服务器3台 两个standard节点(这两个节点直接可以互切primary secondary). 一个arbiter节点 ...
- mongodb replica set 配置高性能多服务器详解
mongodb的多服务器配置,以前写过一篇文章,是master-slave模式的,请参考:详解mongodb 主从配置.master-slave模式,不能自动实现故障转移和恢复.所以推荐大家使用mon ...
- (1)解锁 MongoDB replica set核心姿势
副本集Replica Set是一个术语,定义具有多节点的数据库集群,这些节点具有主从复制(master-slave replication) 且节点之间实现了自动故障转移. 这样的结构通常需要具有奇数 ...
- MongoDB replica set IDs do not match
在搭建MongoDB(版本 3.2.9)的Replica Set时,使用 rs.status() 查看Replica Set的状态,发现一个成员异常:replica set IDs do not ma ...
- MongoDB Replica Set 选举过程
什么是选举? 选举是副本集选择某个成员成为primary的过程.primary是一个副本集中唯一能够接收写操作的成员. 下面的事件能够引发一次选举: 第一次初始化一个副本集 Primary失效.rep ...
随机推荐
- 凸优化 Convex Optimization PDF 扫描文字识别版
凸优化理论 Convex Optimization 清华大学出版社 王书宁许窒黄晓霖译 Stephen Boyd Lieven Vandenbergt原著 2013 年l 月第1 版 下载链接 链接: ...
- 关于Bootstrap的整理和理解
随着CSS3和HTML5的流行,我们的WEB页面不仅需要更人性化的设计理念,而且需要更酷的页面特效和用户体验.作为开发者,我们需要了解一些宝贵的CSS UI开源框架资源,它们可以帮助我们更快更好地实现 ...
- LeetCode题解 #155 Min Stack
写一个栈,支持push pop top getMin 难就难在在要在常量时间内返回最小的元素. 一开始乱想了很多东西,想到了HashMap,treeMap,堆什么的,都被自己一一否决了. 后来想到其实 ...
- C语言运算符优先级和口诀 (转)
一共有十五个优先级: 1 () [] . -> 2 ! ~ -(负号) ++ -- &(取变量地址)* (type)(强制类型) sizeof 3 ...
- python asyncio 异步实现mongodb数据转xls文件
from pymongo import MongoClient import asyncio import xlwt import json class Mongodb_Transfer_Excel( ...
- C# 读取文件中的sql语句 创建数据库以及表结构
大概思路是: 读取文件 根据文件中行内容为GO 作为分割 一条条放到list中 然后在程序中逐条执行sql语句; 值得一提的是 创建数据库的语句是不允许放到程序事务中执行的 所以目前我是分了两个文本 ...
- 优化tomcat配置(从内存、并发、缓存3个方面)优化
Tomcat有很多方面,我从内存.并发.缓存三个方面介绍优化方法. 一.Tomcat内存优化 Tomcat内存优化主要是对 tomcat 启动参数优化,我们可以在 tomcat 的启动脚本 catal ...
- 利用Chrome的Performance工具排查页面性能问题(原叫timeline)
当页面中发生卡顿,最先考虑的是swf文件造成的卡顿,经过排查发现不是swf造成的影响,利用Chrome的Performance工具发现页面中的一些元素不断在重新布局,造成潜在的性能瓶颈. 首先在Chr ...
- resolve或reject之后还需要return吗
答案: 需要 今日碰到一个问题, 是我的同事发现的,如果不说的话可能一直没有注意到 这个代码 在reject 后还会执行, 但是谁也没有注意到, 但是不会报错, 因为当一个promise是resolv ...
- SpringBoot23 分模块开发
1 开发环境说明 JDK:1.8 MAVEN:3.5 IDEA:2017.2.5 SpringBoot:2.0.3.RELEASE 2 创建SpringBoot项目 2.1 项目信息 2.2 添加项目 ...