Create an instance in MongoDB master-slave mode

Source: Internet
Author: User
Tags install mongodb

Create an instance in MongoDB master-slave mode

For databases, the master-slave architecture mode is often used to ensure data security and high availability. for Mongodb, this article describes how to build a simple Mongodb master-slave architecture model.

In the following example, an experiment is performed on one server because there are not multiple servers. Different port numbers are used to distinguish the master and slave nodes.

First, we need to download the official version of Mongodb. Here I download the Linux version 2.4.1, decompress it under Linux, and then create two folders: master and slave, store the primary Mongodb instance and the secondary mongodb instance respectively.


Then we start the primary Mongodb instance in the master, as shown below:

We can see that Mongodb has been waiting for the client to connect to port 27017, and from "master: true", we can see that the current Mongodb instance is started as a master.

Next, we start the slave Mongodb instance and specify that the slave Mongodb is the slave instance of the primary Mongodb,

Mongod -- port 27018 -- dbpath =/lingxi/local/mongodb/slave/mongodb/mongodbdata/-slave-source 172.31.4.15: 27017

Here we will start from the Mongodb instance at Port 27018 and act as the slave instance of the Mongodb instance on port 27017. The startup code is as follows:


The above marked red shows that Mongodb has been started from the instance. The next step is to verify the master-slave mode. Here, we only perform a simple test. We write a piece of data to the primary Mongodb to see if there is data on the Mongodb instance.

 

In the preceding example, a new set is created, a new test set is inserted, and a document {"caller": "18326149379"} is inserted "}, then we insert a document again to see if Mongodb can get new data from the instance in time during the insertion process, as shown below:

As a result, the Mongodb instance can learn the data changes and synchronize the data of the primary Mongodb instance in a timely manner. Now, a simple Mongodb master-slave mode is set up.

It should be noted that, because the master-slave mode also has some problems, to address these problems, Mongodb has other methods to better solve them, therefore, Mongodb officially recommends that you do not use the high-availability solution provided by the Mongodb master. Instead, you should use the replicaset and sharding technology. To address this problem, I will sort out an article to explain it, thank you.

For more MongoDB tutorials, see the following:

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

MongoDB beginners must read (both concepts and practices)

MongoDB Installation Guide for Ubunu 14.04

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

Nagios monitoring MongoDB sharded cluster service practice

Build MongoDB Service Based on CentOS 6.5 Operating System

MongoDB details: click here
MongoDB: click here

This article permanently updates the link address:

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.