MongoDB (Replica set)

Source: Internet
Author: User
Tags mongodb version

A replica set is a cluster configuration method under MONGO:

1, the main node data is synchronized to the replica node by Oplog, Oplog does not log the query statement (because it does not change the data);

2, MONGO replica set can have a master node, multiple replica nodes, the master node is automatically elected;

This article describes a basic replica cluster in a stand-alone configuration, operating system Windows7,mongodb version 2.6.4

1. Create master node, replica node database folder master/db and replset/db

2. Start the database instance of the master node and replica node as follows:

Mongod.exe--dbpath. /master/db--port 10000--replset REPL

Mongod.exe--dbpath. /replset/db--port 20000--replset repl

3, arbitrary landing a node, configuration copy

Mongo.exe localhost:10000

Use admin

Config = {_id: "Repl", Members:[{_id:0,host: "localhost:10000"},{_id:1,host: "localhost:20000"}]}

Rs.initiate (config);//Configure replica set

After the configuration is successful, the Rs.status () command can be queried with the following feedback:

That is, 20000 port is the main point, 10000 port is the replica node

4. Testing

We log in to the master node for data writing:

Go to query from node:

Note: You must turn on Read permissions from the node, as follows

We can find the Oplog record in the local database of the node:

MongoDB (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.