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