Introduction
In this tutorial, we will study how to setup MongoDB Replica Sets using a Spring Data MongoDB-based application for testing our replica sets. We will not create a MongoDB application here but instead we will reuse an existing one from the Spring MVC 3.1 - Implement CRUD with Spring Data MongoDB guide. For this study, we will use production-ready, cloud servers to demonstrate in real-time the results.Table of Contents
Part 1: IntroductionPart 2: Installation and configuration of Replica Sets
Part 3: Spring app configuration
Part 4: Testing the servers
What is a Replica Set?
Replica sets are a form of asynchronous master/slave replication, adding automatic failover and automatic recovery of member nodes.
- A replica set consists of two or more nodes that are copies of each other. (i.e.: replicas)
- The replica set automatically elects a primary (master). No one member is intrinsically primary; that is, this is a share-nothing design.
- Drivers (and mongos) can automatically detect when a replica set primary changes and will begin sending writes to the new primary.
Replica sets have several common uses:
- Data Redundancy
- Automated Failover / High Availability
- Distributing read load
- Simplify maintenance (compared to "normal" master-slave)
- Disaster recovery
Source: MongoDB Replica Sets
Servers
We have four cloud servers (for security purposes, I have modified their actual IP addresses). All servers are running with the following configuration:OS: CentOS release 5.2 (Final) RAM: 512MB HD: 30GB
Here are our servers:
Server # | IP address | MongoDB port | Comments |
---|---|---|---|
Server 1 | 123.456.78.90 | 27017 | primary server |
Server 2 | 123.456.78.91 | 27017 | slave server |
Server 3 | 123.456.78.92 | 27017 | slave server |
Server 4 | 123.456.78.93 | 27017 | arbiter server (see note below) |
Although Server 1 is the primary server, this is not permanent. Whenever the primary server is down, another server is elected as a primary. Server 4 is an arbiter server which is useful for certain cases in electing a primary server.
Note: Our Spring Data MongoDB-based application is hosted in Server 1.
What is an Arbiter?
Arbiters are nodes in a replica set that only participate in elections: they don't have a copy of the data and will never become the primary node (or even a readable secondary). They are mainly useful for breaking ties during elections (e.g. if a set only has two members).
When to add an arbiter
- Two members with data : add an arbiter to have three voters. 2 out of 3 votes for a member establishes it as primary.
- Three members with data : no need to add an arbiter. In fact having 4 voters is worse as 3 of 4 needed to elect a primary instead of 2 of 3. In theory one might add two arbiters thus making number of votes five, and 3 of 5 would be ok; however this is uncommon and generally not recommended.
- Four members with data : add one arbiter.
Source: MongoDB - Adding an Arbiter
Do I need an Arbiter?
You need an arbiter if you have an even number of votes. As an extension to this, at most you should only ever have 1 arbiter. If you aren't sure how many votes you have, it's probably the same as the number of servers in the set you have (including slaves, hidden, arbiters).
Source: Does My MongoDB Replica Set Need An Arbiter?
Next
In the next section, we will install MongoDB on our servers and configure Replica Sets. Click here to proceed.
Share the joy:
|
Subscribe by reader Subscribe by email Share
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteSpring online training Spring online training Spring Hibernate online training Spring Hibernate online training Java online training
spring training in chennai spring hibernate training in chennai
I vote both, when I vote down I definitely state why. I think that if someone voted down without a comment I would find the person and ask why they voted down.
ReplyDeletesubway surfers
I enjoyed your blog Thanks for sharing such an informative post. We are also providing the best services click on below links to visit our website.
ReplyDeletedigital marketing company in nagercoil
digital marketing services in nagercoil
digital marketing agency in nagercoil
best marketing services in nagercoil
SEO company in nagercoil
SEO services in nagercoil
social media marketing in nagercoil
social media company in nagercoil
PPC services in nagercoil
digital marketing company in velachery
digital marketing company in velachery
digital marketing services in velachery
digital marketing agency in velachery
SEO company in velachery
SEO services in velachery
social media marketing in velachery
social media company in velachery
PPC services in velachery
online advertisement services in velachery
online advertisement services in nagercoil
web design company in nagercoil
web development company in nagercoil
website design company in nagercoil
website development company in nagercoil
web designing company in nagercoil
website designing company in nagercoil
best web design company in nagercoil
web design company in velachery
web development company in velachery
website design company in velachery
website development company in velachery
web designing company in velachery
website designing company in velachery
best web design company in velachery
Thanks for Sharing - ( Groarz branding solutions )