MongoDB Master-slave replication is a master data snapshot that does not need to be completed in advance from the database like MySQL
Background: MongoDB supports one master one from or multiple copies from
1) Master node:
Mongod--dbpath=/usr/mongodb/data/--logpath=/usr/mongodb/log/mongodb.log--master
# #可选--oplogsize--directoryperd main node oplog size (in megabytes)
2) Slave node:
Mongod--dbpath=/usr/mongodb/data/--logpath=/usr/mongodb/log/mongodb.log--slave--source masterIP:27017-- Autoresync
# # #autoresync自动同步不一致数据
4) Parameters:
A)-only
Specify that only a specific database is replicated on the slave node (all databases are replicated by default)
b)-slavedelay
Used on the slave node to increase the delay (in seconds) when the operation of the master node is applied.
c)-fastsync
Initiates a Slave node based on the data snapshot of the master node. If the data catalog starts with a data snapshot of the master node, booting from the node with this option is much faster than doing a full synchronization.
D)-autoresync
Automatic resynchronization if the slave node is out of sync with the primary node (at a higher cost)
5) View master-slave replication status
Use local
Rs.ismaster ()
Db.printreplicationinfo ()
6) master server local library holds slave information
7) Change the Oplog size. By default, the. Oplog size accounts for 5% of the server's remaining space and should be set as large as possible for security.
Method: 1) Stop MongoDB Service
2) Delete Mognodb Local database
3) Start parameter add--oplogsize 200 (in MB)
4) Restart MongoDB service ()
8) Dynamically add nodes or delete nodes
In the From node
Use local
Db.sources.insert ({"Host": "Ip:port"})
Db.sources.remove ({"Host": "Ip:port"})
MongoDB Primary master replication
Primary master Settings
192.168.129.47 Startup parameters:
Rm/usr/mongodb/log/mongodb.log
/usr/mongodb/bin/mongod--dbpath=/usr/mongodb/data/--logpath=/usr/mongodb/log/mongodb.log--master--slave-- SOURCE 192.168.129.48:27017
192.168.129.48 Startup parameters:
Rm/usr/mongodb/log/mongodb.log
/usr/mongodb/bin/mongod--dbpath=/usr/mongodb/data/--logpath=/usr/mongodb/log/mongodb.log--master--slave-- SOURCE 192.168.129.47:27017
In both of these scenarios, this scenario is no longer recommended for the latest version of MongoDB (1.6 later). Recommended Replica sets replication Set scheme
MongoDB master-slave replication, primary master replication