Actual Combat MongoDB
Master-slave
MongoDB supports asynchronous data replication between different services to implement failover (failover, failover, failback) and redundancy (data redundancy).
At the same time, only one service node (primary or master) supports writing.
MongoDB supports two modes of replication:
Master/slave, master-slave replication, roles include Master and Slave.
Replica set, replica set replication, roles include primary and secondary.
To introduce the official address of Master/slave:
Http://www.mongodb.org/display/DOCS/Master+Slave
Describes the official address of replica set:
Http://www.mongodb.org/display/DOCS/Replica+Sets
Today's actual combat is replica set, that is, replication set replication.
Replica set can implement automatic failover and automatic recovery.
The replica set consists of two or more nodes, which enable each other to replicate.
Replica set automatically selects the primary node, and no node is fixed primary.
MONGOs automatically discovers that a replica set primary node changes and sends writes to the new primary node.
Typically used for the following scenarios
Data redundancy.
Automatic failover, providing high availability services.
Distributed read load.
Simplifies maintenance (as opposed to master-slave).
Disaster recovery.
First or start Mongod, there are two parameters for the replica set:
--replset <setname>, the name of the replica set.
--oplogsize <mb>, the size of the action log, in megabytes.
This time we configure replica set under Ubuntu and start with two mongod nodes first.
Mongod--dbpath/home/andyshi/mongo1/--logpath/home/andyshi/mongo1/log.log--replset shard1--port 10001--bind_ip 192.168.0.21
Mongod--dbpath/home/andyshi/mongo2/--logpath/home/andyshi/mongo2/log.log--replset shard1--port 10002--bind_ip 192.168.0.21
You will notice that the two mongod boot parameters replset Specify the same value Shard1, that is, two mongod nodes are in the same replica set.