View MongoDB replica set again

Source: Internet
Author: User
Tags install mongodb mongodb version

View MongoDB replica set again

Because MongoDB uses memory ing files, the 64-bit version is required.

Official: http://www.mongodb.org/downloads

Mongodb version used in the lab environment is mongodb-linux-x86_64-2.6.0

Built on three virtual machines, the configuration is single-core and 1 GB memory.

The experiment environment is as follows:

MongoDB replica sets are different from the previous master-slave mode.

When the cluster Master fails, the replica set can automatically vote, elect a new Master, and guide other Slave servers to connect to the new Master,

This process is transparent to applications. It can be said that the replica set of MongoDB is a master-slave replication with the Failover function.

CentOS compilation and installation of MongoDB

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

MongoDB beginners must read (both concepts and practices)

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

1. advantages over the traditional master-slave mode

In the traditional Master-slave mode, you must manually specify the Master in the cluster.

If the Master node fails, manual intervention is generally performed to specify a new Master node.

This process is generally not transparent to applications. It is often accompanied by re-modifying the configuration file and restarting the application server.

MongoDB replica set, any node in the cluster may become a Master node.

If the Master node fails, a new Master node is selected from the other nodes.

And guide the remaining nodes to connect to the new Master node. This process is transparent to applications.

2 Bully Election Algorithm

The Bully algorithm is a coordination (master node) Election algorithm. The main idea is that every member of the cluster can declare it as the master node and notify other nodes.

Other nodes can choose to accept the claim or reject and enter the master node for competition. Only nodes accepted by all other nodes can become the master node.

Nodes determine who should win based on certain attributes. This attribute can be a static ID or an updated metric like the last transaction ID (the latest node will win)

His election process is roughly as follows:

? Obtain the last operation timestamp of each server node. Each apsaradb for mongodb has an oplog mechanism to record local operations, so that you can easily compare data synchronization with the master server and use it for error recovery.

? If most servers in the cluster are down, the active nodes are in the secondary State and stopped.

? If the last synchronization time of the primary node or all slave nodes in the cluster looks old, stop the election waiting for the person.

? If there is no problem above, select the server node with the latest operation timestamp (ensure the data is up-to-date) as the master node.

Conditions for triggering an election

Initialize a replica set.

The replica set and master node are disconnected, which may be caused by network problems.

The master node fails.

Manual intervention, such as modifying node priority

There is also a precondition for the election. The number of nodes participating in the election must be more than half of the total number of nodes in the replica set. If the number is less than half, all nodes are read-only.

3. Build a replica Set cluster

Each virtual machine uses the following configuration file to start the instance:

Dbpath =/home/lihuilin/export data

Smallfiles = true

ReplSet = mvbox

Log on to mongo from any virtual machine and enter the following settings.

Config = {_ id: "mvbox", members :[

{_ Id: 0, host: "192.168.1.1: 27017 "},

{_ Id: 1, host: "192.168.1.2: 27017 "},

{_ Id: 2, host: "192.168.1.3: 27017"}]

}

Rs. initiate (config );

The replica set has taken effect.

You can use rs. status () to view the cluster status or rs. isMaster ()

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • 3
  • Next Page

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.