MongoDB single-host, master-slave, distributed deployment

Source: Internet
Author: User

MongoDB is the most easy-to-use NoSQL and is suitable for replacing MySQL for some storage, but it is not highly consistent. This article introduces various MongoDB deployment methods and shares some experiences. The first two parts, "single-host deployment" and "master-slave deployment", are the basis of "multipart deployment.

MongoDB single-host deployment

Start mongod.exe under the BIND directory of the downloaded mongodbpackage to open the MongoDB service. The basic configuration you can add is:

./Mongod.exe -- dbpath ~ /Db/data -- port 10000 -- logpath ~ /Db/log

The default port is 27017. At startup, you must have a data directory for mongod to read and write data. After data is written, the files in the data Directory

If the. lock file still exists at the next startup, You need to delete it to start it successfully. "Article" and "config" are database names. Pay special attention to the size of each file block (16 M, 32 M, 64 M, 128 M ).

MongoDB master-slave deployment

The master-slave configuration is one of the characteristics of MongoDB, which provides performance such as fault tolerance and fault recovery. The master node declares "master", and the slave node declares "slave" and "-- source ". The simplest Master/Slave configuration is as follows:

./Mongod.exe -- dbpath ~ /Db/master -- port 10000 -- master

./Mongod.exe -- dbpath ~ /Db/slave -- port 10001 -- slave -- source localhost: 10001

The slave node synchronizes data directly from the master node, but not from each other. A highly fault-tolerant deployment is a master-slave cluster that can become a "master node" and is called a Replica Set. There is an active node and several backup nodes in the Replica Set. During configuration, the entire Replica Set should have a name, and each table must specify one or several partners:

./Mongod.exe -- dbpath ~ /Db/node1 -- port 10001 -- replSet setname/localhost: 10002

./Mongod.exe -- dbpath ~ /Db/node2 -- port 10002 -- replSet setname/localhost: 10001

./Mongod.exe -- dbpath ~ /Db/node3 -- port 10003 -- replSet setname/localhost: 10001

The priority of an active node depends on the priority. The default priority is 1. You can also enable mongod to set the priority (not specific). In short, it is an internal election mechanism.

  • 1
  • 2
  • Next Page

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: 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.