MongoDB Basic Cluster Administration
ch2 Replication
MongoDB Replica Set
- Replica set are groups of mongod
- High availability and Failover
- Members can have different roles and specific purposes
election trigger
- Adding a new node to the replica set,
- initiating a replica set,
- performing replica set maintenance using methods such as rs.stepDown() or rs.reconfig()
- the secondary members losing connectivity to the primary for more than the configured timeout (10 seconds by default).
Setting Up a Replica Set
Use setting file demo
Replication Configuration Document
Replication Configuration
- JSON Object that defines the configuration options of our replica set
- Can be configured manually from the shell
- There are set of mongo shell replication help make it easyer to manage
- rs.add
- rs.initiate
- rs.remove
- rs.status
- rs.config
- rs.reconfig
Replication Commands
Local DB
- me
- oplog.rs
- replset.election
- replset.minvalid
- startup_log
- system.replset
- system.rollback_id
Usually, do not modify them.
Any data written to local database is not written to oplog.rs or changing any of the system configuration collections will stay there and will not be replicated
- capped collection
- takes 5% of free disk by default
Reads and Writes on a Replica Set
To enable to read on secondary node
We can never write to secondary node