MongoDB replica Set Configuration

Source: Internet
Author: User
Tags mongodb client

There are three types of replica set nodes:

    • Standard: a regular node that stores a complete copy of data and participates in voting. It may become a primary node;
    • Passive: stores complete copies of data and participates in voting. It cannot be a primary node;
    • Arbiter: An arbitration node that only participates in voting and does not receive copied data. It cannot become a primary node.

In this article, two common nodes and one arbiter node are configured. Because the arbiter node does not synchronize data, the load is very small and the deployment does not require much hardware.

Assume that 192.168.1.211 and 192.168.1.212 are regular nodes, and 192.168.1.68 are arbiter nodes. MongoDB on the three nodes uses the following configuration file, which is stored in/etc/MongoDB. CNF:

 
Dbpath =/data/DB/logpath =/data/log/M. logappend = trueport = 27017 fork = truedirectoryperdb = truejournal = truereplset = testrest = true

Replset ID is test, which corresponds to "_ id" In initiate. After using the rest parameter, you can display information about other MongoDB instances in replica set on the Web management interface.

Use commands

 
/Usr/local/MongoDB/bin/mongod -- config/etc/MongoDB. CNF

Start the MongoDB instances on each of the three machines and use the MongoDB client to log on to either of the two common nodes. Run the following command:

Rs. initiate ({"_ id": "test", "members": [{"_ id": 1, "host": "192.168.1.211" },{ "_ id ": 2, "host": "192.168.1.212" },{ "_ id": 3, "host": "192.168.1.68", "arbiteronly": true}]}); or Rs. initiate ({"_ id": "test", "members": [{"_ id": 1, "host": "192.168.1.211" },{ "_ id ": 2, "host": "192.168.1.212"}]}); RS. addarb ('2017. 168.1.68 ');

You can use Rs. conf () to view the configuration, Rs. status () to view the status of each node. after a short period of time, they will select one as the primary, and other common nodes will be secondary, in the JS shell, you can also see that the prompt changes from ">" to "primary>", "secondary>", or "arbiter> ". You can use Rs. Stepdown () to switch to primary in primary. After executing this command, you will select one of the remaining regular nodes to act as primary.

For other optional parameters for configuring members in initialization, go to the official website to view the address: http://www.mongodb.org/display/DOCS/Replica+Set+Configuration

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.