mongodb--the replica set of the architecture (master-slave, replica set)

Source: Internet
Author: User


    • At any point in time there is only one active node, the other is the backup node, when the active node pump, will pass the election rule, select an active node from the alternate node, when the pump node recovers, it becomes the standby node.
    • Node type

Stabdard: Regular nodes, storing full data, participating in polls, potentially becoming active nodes

Passive: Polling node, storing full data backup, not voting, cannot be active node

Arbiter: Quorum node, no data, participate in voting, cannot become an active node

    • Election rules: According to the priority of the node (the number 0-1000 contains 1000) from large to small sort (0 to not become active node), if the priority is the same, then judge the data of the node new and old, the latest node becomes active node, Note: If the latest data for a backup node is synchronized 3 seconds ago, when it becomes an active node, the data that becomes the backup node is up to date, and the data for the other nodes (including the original active node) is rolled back and then synchronized with the current active point. Other nodes cannot be candidates for active nodes until synchronization


    • Environment building, set up file directory ms\set1\db, log, config file ms\set2\db, log, config file ms\set2\db, log, config file

1. The configuration file is as follows:

Example 1

Dbpath=d:\msset\set1\db

Logpath=d:\msset\set1\s1.log

Directoryperdb=true

Logappend=true

replset=testrs/127.0.0.1:28882

port=28881

oplogsize=10000


Example 2

Dbpath=d:\msset\set2\db

Logpath=d:\msset\set2\s2.log

Directoryperdb=true

Logappend=true

replset=testrs/127.0.0.1:28881

port=28882

oplogsize=10000


Example 3

Dbpath=d:\msset\set3\db

Logpath=d:\msset\set3\s3.log

Directoryperdb=true

Logappend=true

replset=testrs/127.0.0.1:28882 (configuration file specifies that Replset is the name of the replica cluster associated with the corresponding IP, can only associate one, after the start MONGO can automatically sense the other machine cluster)

port=28883

oplogsize=10000


2. Use the Mongod command to start the instance service. Mongod--config D:\MSset\Set1\conf.conf (The following 2 instance launch commands are identical)

3. Use the MONGO command to log in one of the instances, MONGO 127.0.0.1:28882

Because the use of the configuration file is only a physical association, you need to manually execute the command to string up the cluster, at this time the login server can not do read, write operations,

You need to execute the command, Db.getmongo (). Setslaveok () to read and write permissions, then execute the command to concatenate each instance MONGO

Db.runcommand ({
"Replsetinitiate": {
"_id": "Testrs",
"Members": [
{
"_id": 1,
"Host": "127.0.0.1:28881"
},
{
"_id": 2,
"Host": "127.0.0.1:28882"
},
{
"_id": 3,
"Host": "127.0.0.1:28883"
}
]
}
})



Project file:

Http://pan.baidu.com/s/1o8lwcUA

mongodb--the replica set of the architecture (master-slave, replica set)

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.