Set up MongoDB Master-Slave replication (Master-Slave) Set

Source: Internet
Author: User
Tags install mongodb node server
Master-slave replication is a feature of MongoDB databases. It uses data backup to improve database disaster tolerance. However, because master-slave replication cannot automatically implement failover, Mon

Master-slave replication is a feature of MongoDB databases. It uses data backup to improve database disaster tolerance. However, because master-slave replication cannot automatically implement failover, Mon

Master-slave replication is a feature of MongoDB databases. It uses data backup to improve database disaster tolerance. However, because master-slave replication does not automatically implement failover, MongoDB has developed a new replication mode: Replicate Sets in version 1.6. MongoDB does not recommend that you back up data in Master-Slave mode. However, we can still learn about the master-slave replication mode of MongoDB.

1. download the latest version of MongoDB from the official MongoDB website and decompress it to a directory.

2. In the MongoDB folder, create the/data/master and/data/slave directories.

3. Start the Master node server and run the following command:

Mongod -- dbpath/data/master -- port 10000 -- master

After running the preceding command, mongodb generates data files and log files under data/master.

4. Start the server on the Slave node (Slave) and run the following command:

Mongod -- dbpath/data/slave -- port 10001 -- slave -- source localhost: 10000

After the preceding command is executed, data files and log files are generated under data/slave, and the associated information with the master is created under the sources table in the local database.

5. Test whether Master-Slave replication (Master-Slave) takes effect.

Use "mongo localhost: 10000" to open the Master database and insert a test statement:

Db. test. find ();

Db. test. insert ({"host": "1000 "});

Db. test. find ();

Run "mongo localhost: 10001" to open the Slave database. Run db. test. find () and you will find that the queried data is the same as the data queried from the Master database.

Run db. test. insert ({"girl": "lili"}); not master is displayed. This is because the Master-Slave replication mode only allows data updates from the Master database, rather than from the Slave database. Therefore, when the Master node fails, the disadvantage of being unable to switch from the Master node to the Master node is exposed.

MongoDB details: click here
MongoDB: click here

Related reading:

MongoDB backup and recovery

CentOS compilation and installation of MongoDB

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

How to create a new database and set in MongoDB

MongoDB beginners must read (both concepts and practices)

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

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.