MongoDB Replica Set Usage experience sharing

Source: Internet
Author: User

MongoDB Replica Set is the officially recommended master-slave replication and high availability scheme for MONGODB, which replaces the original Master-slave master-slave replication scheme. The REPLICAT set has automatic switching, and when primary is hung, it can be automatically switched from one secondary in the replica set to primary for high-availability purposes, unlike MySQL, which requires the use of third-party software.

At present, many game companies have started to use MongoDB as a database, our company online version of the use is 2.4.6.


The principle of a MongoDB Replica set

Replication is primarily used for backup, disaster recovery, and read/write separations. A replica set is a set of Mongod instances. The primary in Replica set receives all writes, secondaries from the primary copy operation and then applies to its own data set.


650) this.width=650; "Src=" Http://docs.mongodb.org/v2.4/_images/replica-set-read-write-operations-primary.png " alt= "Diagram of default routing of reads and writes to the primary."/>


650) this.width=650; "src=" Http://docs.mongodb.org/v2.4/_images/replica-set-primary-with-two-secondaries.png "alt = "Diagram of a 3 member replica set that consists of a primary and a secondaries."/>


650) this.width=650; "Src=" http://docs.mongodb.org/v2.4/_images/ Replica-set-primary-with-secondary-and-arbiter.png "alt=" Diagram of a replica set that consists of a primary, a secondary, and an arbiter. "/>


650) this.width=650; "src=" Http://docs.mongodb.org/v2.4/_images/replica-set-trigger-election.png "alt=" Diagram of An election of a new primary. In a three member replica set with the secondaries, the primary becomes unreachable. The loss of a primary triggers an election where one of the secondaries becomes the new primary "/>




There are three member roles in a replica set: Primary,secondary and Arbiter.


Primary receives all writes from the client, and there is only one Primary in a replica set. Primary if it goes down, Replica set will automatically elect a secondary to become primary. Primary logs all operations of its data sets to Oplog.


Secondary secondary copies Oplog from primary, and then applies the actions in Oplog to its own data sets. Between secondary and primary is asynchronous replication, which means that the data in secondary may not be up to date. By default, secondary is unreadable and not writable, but can be read from secondary by setting the run client.




Arbiter Arbiter does not need to maintain its own data sets, only when the primary is hung up to vote on which secondary can be upgraded to primary. When the number of members in the replica set is an even number, you need to add a arbiter to vote on which can be upgraded to primary. Arbiter requirements for hardware are low. You cannot run arbiter on a primary or secondary host.


A replica set can have up to 12 members, but only 7 members can participate in the voting at the same time to become primary, and if the number of members exceeds 12, the Master-slave master-slave copy method is required.

Deploying a replica set requires at least three members, one arbiter, one secondary and one primary or one primary, and two secondary.



The secondary can be configured for several special purposes:

A. Prevent it from becoming a primary in elections and use it only as backup data. This is achieved by setting priority precedence to zero.

650) this.width=650; "Src=" http://docs.mongodb.org/v2.4/_images/ Replica-set-three-members-geographically-distributed.png "alt=" Diagram of a 3 member replica set distributed across D ATA Centers. Replica set includes a priority 0 member. "/>

B. Block the application from reading it, by setting priority to 0 and setting hidden to true.


650) this.width=650; "src=" Http://docs.mongodb.org/v2.4/_images/replica-set-hidden-member.png "alt=" Diagram of a 5 Member replica set with a hidden priority 0 member. "/>

A hidden member also replicates primary data, but it is not visible to the client application.


C. Preserving historical image data for data back-up, such as data recovery from delayed Replica set members if data is deleted by mistake.

650) this.width=650; "src=" Http://docs.mongodb.org/v2.4/_images/replica-set-delayed-member.png "alt=" Diagram of a 5 Member replica set with a hidden delayed priority 0 member. "/>

Delayed members that delay member will delay copying from primary Oplog




Reference documents

http://docs.mongodb.org/v2.4/replication/


This article is from the Linux SA John blog, so be sure to keep this source http://john88wang.blog.51cto.com/2165294/1598982

MongoDB Replica Set Usage experience sharing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.