MongoDB replica set Replset configuration and analysis

Source: Internet
Author: User
Tags failover mongodb
2 standard nodes + 1 arbiter nodes build MongoDB Replication Sets
Creating a Catalog [root@localhost ~]# mkdir-p/data/replset/r0 [root@localhost ~]# mkdir-p/data/replset/r1 [root@localhost ~]# mkdir -P/DATA/REPLSET/R2 [root@localhost ~]# mkdir-p/data/replset/key [root@localhost-~]# mkdir-p/data/replset/log

Create key [Root@localhost ~]# echo "Replset1 key" >/data/replset/key/r0 [root@localhost ~]# echo "Replset1 key" >/data /REPLSET/KEY/R1 [Root@localhost ~]# echo "Replset1 key" >/data/replset/key/r2 [root@localhost ~]# chmod 600/data/repl set/key/r*//600 to prevent other programs from overwriting this key

/apps/mongo/bin/mongod--dbpath=/data/replset/r0--replset replset1--keyfile/data/replset/key/r0--port 28010
/apps/mongo/bin/mongod--dbpath=/data/replset/r1--replset replset1--keyfile/data/replset/key/r1--port 28011
/apps/mongo/bin/mongod--dbpath=/data/replset/r2--replset replset1--keyfile/data/replset/key/r2--port 28012
Note: After--keyfile/data/key/r0 adds this, Mongvue can't even reach the


Use the following on the line (this is for easy to see the log, directly on the command line output view)
/apps/mongo/bin/mongod--dbpath=/data/replset/r0--replset replset1--port 28010
/apps/mongo/bin/mongod--dbpath=/data/replset/r1--replset replset1--port 28011
/apps/mongo/bin/mongod--dbpath=/data/replset/r2--replset replset1--port 28012

Official run to run in the background with the following:
/apps/mongo/bin/mongod--dbpath=/data/replset/r0--replset replset1--port 28010--logpath=/data/replset/log/r0.log- -logappend--fork--directoryperdb
/apps/mongo/bin/mongod--dbpath=/data/replset/r1--replset replset1--port 28011--logpath=/data/replset/log/r1.log- -logappend--fork--directoryperdb
/apps/mongo/bin/mongod--dbpath=/data/replset/r2--replset replset1--port 28012--logpath=/data/replset/log/r2.log- -logappend--fork--directoryperdb


Initialize replica set:
/apps/mongo/bin/mongo--port 28010
Config_replset1 = {_id: "Replset1", Members: [{_id:0,host: "127.0.0.1:28010", Priority:4}, {_id:1,host: " 127.0.0.1:28011 ", Priority:2}, {_id:2,host:" 127.0.0.1:28012 ", Arbiteronly:true}]}
Note that the Arbiter quorum node only votes and does not receive replicated data!


Rs.initiate (CONFIG_REPLSET1);

/apps/mongo/bin/mongo--port 28010/apps/mongo/bin/mongo--port 28011/apps/mongo/bin/mongo--port 28012
//write a piece of data to primary

//secondary cannot write, and after setting Slaveok, it is possible to read data from secondary
By default, secondary can not read and write, to set Db.getmongo (). Setslaveok (); only one Replset library can be read from secondary primary, and only data from primary will be written. Cannot write data to secondary
//arbiter Read writes are not
Note that the Arbiter quorum node only votes, does not receive replicated data!, does not receive primary writes the MYDB the data!


From the Arbiter node, arbiter only holds the configuration information of the replica set in Local.system.replset, and no oplog.rs, and arbiter does not receive primary written MYDB data! Description Arbiter " Just voting, not receiving replicated data "!

look at Primary's local.slaves, see only one slave (not two), this slave is secondary node, where arbiter node is not primary slave, This also means that arbiter "only vote, not to receive replicated data"!

Failover testing:
CTRL + C to exit the primary process, primary node 28010 down,

look at the originalSecondary (28011) node,
And look at the Arbiter node (28012)
After the primary node 28010 down, arbiter votes to secondary 28011 and secondary becomes the new primary node.

Summary: 1: When the total number of votes for a replica set is even, there may be situations where the master node cannot be elected, and Mongod prompts:
2 standard nodes make up replication sets is unreasonable, because it does not have the ability to failover!
A: When the secondary down, there is a primary, the replica set does not run problems, because you do not have to select Primary node B: When the primary down, at this time the replica set only one secondary, it only 1 votes, not more than half of the total number of nodes , it will not elect itself for the primary node!
The prompts are as follows:




3 standard nodes composed of replication sets can be, when the primary node down or you can select a primary node, at this point to immediately repair down machine node, Because not repaired if the current primary node is down again, one secondary node is not able to pick the primary node!
feasible scenario: 3 standard nodes or 2 standard nodes + 1 arbiter nodes
Personal feeling if you have only 2 servers, you can deploy high priority standard to 1 high-performance servers, and then deploy another standard node + 1 arbiter nodes to another server so that primary nodes are on 1 servers, Secondary node and arbiter nodes and another server, so that no matter which node is broken, Replset can also serve
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.