The Master-slave of actual combat mongodb-replication

Source: Internet
Author: User
Tags command line failover log mongodb

01.

Welcome to use ueditor!

MongoDB supports asynchronous data replication between different services to implement failover (failover, failover, failback) and redundancy (data redundancy).

At the same time, only one service node (primary or master) supports writing.

MongoDB supports two modes of replication:

Master/slave, master-slave replication, roles include Master and Slave.

Replica set, replica set replication, roles include primary and secondary.

To introduce the official address of Master/slave:

Http://www.mongodb.org/display/DOCS/Master+Slave

Describes the official address of replica set:

Http://www.mongodb.org/display/DOCS/Replica+Sets

Today's actual combat is Master-slave, that is, master-slave replication.

Start the service using Mongod first, and the parameters for startup can be found in the Http://www.mongodb.org/display/DOCS/Command+Line+Parameters page.

The following are some of the parameters used for master-slave copying:

--master, indicating that the current service is the master.

--slave, indicating that the current service is from.

--source, indicating the address of the main service, in the form of Server:port.

--only <db>, indicating that the specified database is currently copied from only the master, and that the database name is in DB.

The start service can specify a single parameter from the command line, or you can store the parameters in a file, and then start by specifying the file as the service's configuration file. The following methods are easy to manage and maintain, recommended for use.

First configure the main service.

01.port=30000
02.ddbpath=d:\mongodb\master1
03.directoryperdb=true
04.logpath=d:\mongodb\master1\log.log
05.logappend=true
06.master=true
07.bind_ip=192.168.0.111

Configure the parameters as shown above, copy the parameters above to a file, name "Master1.conf", and then use the following command to start the main service.

D:\mongodb\bin\mongod--config=d:\mongodb\master1\master1.conf

Above is the command initiated in Windows.

If used in Ubuntu, assume that the conf file is stored in the/home/andyshi/master1/directory, the Conf file content modified as follows.

port=30000 
dbpath=/home/andyshi/master1 
directoryperdb=true
logpath=/home/andyshi/master1/log.log 
logappend=true
master=true
bind_ip=192.168.0.111

Use the following command to start the main service.

Mongod--conf=/home/andyshi/master1/master1.conf

It is noted that the main difference is the location of the catalogue, pay attention to it.

Then you can use the MONGO client to test the results of our configuration, or use Python+pymongo can also be tested, by the way familiar with the use of Python+pymongo.

Our client test environment uses ubuntu+python2.7+pymongo2.1.

Enter in the terminal

MONGO 192.168.0.111:30000

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.