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