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)