MongoDB Master-slave replication

Source: Internet
Author: User

The specific main of master-slave replication is to modify the mongodb.conf configuration file for two hosts

MongoDB supports one master multiple from replication (different instances in the/data directory to create different directories)

Master configuration file

DBPath =/data/mongodb/data/

LogPath =/data/mongodb/logs/mongodb.log

Logappend = True//true Add a new entry at the end of the log file instead of overwriting the contents of the log at the restart process

SLOWMS=500//Turn on slow query

Fork = True

Port = 27017

Profile = 1

Oplogsize = 10000

Master = True

Pidfilepath =/tmp/mongodb.pid

Auth=true

bind_ip=10.33.5.226

Nohttpinterface = ture//disable access to HTTP interface

From the configuration file

DBPath =/data/mongodb/data/

LogPath =/data/mongodb/logs/mongodb.log

Fork = True

Port = 27017

Profile = 1

Oplogsize = 10000//maximum size of the specified copy operation log

#master = True

Slave = True

Source = 61.147.187.204:27017

Pidfilepath =/tmp/mongodb.pid

Auth=true

bind_ip=10.33.5.226

Nohttpinterface = ture

ONLY=TESTDB//Specify the database to be replicated

SLAVEDELAY=60//Set the delay time from the library

Autoresync=true//Whether automatic resynchronization, set to True, if the main behind more than 10 seconds, will force from automatic resynchronization

If the oplogsize is too small, there may be a problem with this setting. If the Oplog size is not large enough to store the difference between the change state of the master and the change from the state, forcing resynchronization in this case is not necessary. When the Set Autoresync option is set to false,10 in minutes, no automatic resynchronization is made greater than 1 times.

When the master/slave configuration file has been modified, specify the corresponding profile () when it is started

/usr/local/mongodb/bin/mongod-f/data/mongodb/etc/mongodb.conf

Login to MongoDB (before logging in Auth option to comment out the configuration file, rebuild the root user and then turn on change authentication)

At the same time in the master-slave host, the local database to create REPL user user synchronization, the same account password

/usr/local/mongodb/bin/mongo admin--host 121.207.243.90-u root-p--port 37017

View Master-slave replication status

Db.printreplicationinfo ();

This article from "Banging blog" blog, declined reprint!

MongoDB Master-slave 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.