MongoDB Database Learning Series ———— (i) The construction of the master-slave copy of MongoDB database

Source: Internet
Author: User
Tags mongodb support

The construction of the master-slave copy of MongoDB database

Writeby:lipeng date:2014-10-22

Recent projects using the location query, on the Internet to see the MongoDB support distance query, so I learned a bit mongodb, in the study summed up the problems encountered and solutions, as well as MongoDB installation, master-slave replication, clustering and in. NET application of the operation, recorded to facilitate their own later use to get, but also hope to help those who learn MongoDB, I have just learned mongodb, there are problems hope everyone reminded out, learn from each other, common progress.

1. Preparation

Windows operating system computer one, in the e-disk new two folders to store the main database and from the database, the configuration file in the main database is as follows:

Where port, DBPath is the location of database files, logpath log file storage location

Note: Master=true represents the primary server.

The configuration file from the server is as follows:

Where port is the port number, DBPath is the location of the database file, and the location of the LogPath log file is stored.

Note: Slave=true represents the primary server. SOURCE=127.0.0.1:27017 represents the server from which the database files are synchronized.

2. Concrete implementation
    1. To open a CMD command operation, execute the following command:

Where: Enter the location of the configuration file after--config,

After successful startup, the following is displayed:

At this point, the primary server has started successfully.

2. Open a CMD operation again and execute the following command:

Where: Enter the location of the configuration file after--config

After successful startup, the following is displayed:

The server is now open.

3. Open the Home Server page: http://localhost:28017/----Note the port number plus 1000 as follows:

can see:

3. Open the Web page from the server: http://localhost:13548/----Note the port number plus 1000 as follows:

can see:

3. Testing

Enter the following command in the shell of the primary server: Db.test.save ({"11", 123})

Enter the following command in the shell from the server: Db.test.find () The result is as follows:

The test results indicate that master-slave replication is complete.

4. Problems encountered and solutions
    1. Time to start MongoDB error; Can not read from Mongdb.config. This error can occur because the path to the profile is not correctly written or the parameters of the configuration file are not written correctly.
    2. The error is as follows:

The reason for this error is that the port number being opened is already in use, and a new one will start normally.

MongoDB Database Learning Series ———— (i) The construction of the master-slave copy of MongoDB database

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.