MongoDB master-slave replication, primary master replication

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.