The structure of MongoDB Replica sets is similar to clustering, which can be considered as a cluster, because he does the same thing as the cluster implementation: if one of the nodes fails, the other nodes will take over the business immediately. Without the need for down operation
Configuration steps for MongoDB Replica sets:
1: Start three nodes
(Mongodb\mongodb\bin\ is the folder where MONGO is located)
Start a 1th node:
Mongodb\mongodb\bin\mongod--replset rs3/127.0.0.1:28011,127.0.0.1:28012--port 28010--oplogSize--dbpath d:\ Mongodb\data\data\r0--logpath=d:\mongodb\data\log\log.log--logappend
Start a 2nd node:
Mongodb\mongodb\bin\mongod--replset rs3/127.0.0.1:28010,127.0.0.1:28012--port 28011--oplogSize--dbpath d:\ MONGODB\DATA\DATA\R1--logpath=d:\mongodb\data\log\log1.log--logappend
Start a 3rd node:
Mongodb\mongodb\bin\mongod--replset rs3/127.0.0.1:28010,127.0.0.1:28011--port 28012--oplogSize--dbpath d:\ MONGODB\DATA\DATA\R2--logpath=d:\mongodb\data\log\log2.log--logappend
Describe the parameters involved
--oplogsize Log operation file is large
--dbpath Data File path
--logpath log file path
--port port number, default is 27017. This is the port number I'm using here.
--replset the name of the replica set, the parameter for each node in a replica sets is given a copy set name, here is test.
--replset test/This is followed by the IP and port of the other standard node
--maxconns Maximum number of connections
--fork Background Run
--logappend log files are recycled, and if the log file is full, the new log is overwritten with the longest log.
--keyfile identifies the authentication private key for the same cluster
Where you start the node must be added oplogsize parameters to set its size, otherwise on the 64-bit operating system mongodb,oplogs are quite large-may be 5% of the disk space, to set a reasonable value according to the situation.
2: Configure node information
Select a node to execute the following command in turn:
MONGO--port 28010
confinre={_id: ' Rs3 ', members:[{_id:0,host: ' 127.0.0.1:28010 ', priority:1},{_id:1,host: ' 127.0.0.1:28011 '},{_id:2, Host: ' 127.0.0.1:28012 '}]}
Rs.initiate (confinre)
Rs.status ()
The results of the implementation are as follows:
The replica Set schema of Mongodb is stored by a fixed-length capped collection called Oplog for logging replica sets operations logs. It exists with the local library.
The configuration information for Mongodb's replica set is stored in the System.replset collection
3: Read and write separation
4: Fail over
The MongoDB of one node is abnormal, the system automatically sets the other node as the main library
Section reference: http://blog.csdn.net/bloggongchang/article/details/7272403