MongoDB primary, secondary, quorum node cluster installation

Source: Internet
Author: User
Tags create mongodb

MongoDB's cluster approach is divided into three types of replica set/sharding/master-slaver, here only the simplest way to build a cluster (production environment), if there are multiple nodes can be and so on or view official documents.

Replica Set

Chinese translation is called a replica set. In fact, the simple is that the cluster contains a number of data, to ensure that the main node hangs, the standby node can continue to provide data services, provided the premise is that the data needs and the main node consistent. Such as:

MongoDB (M) represents the primary node, MongoDB (S) represents the standby node, and MongoDB (A) represents the quorum node. The primary and standby node stores data (M,s), and the quorum node does not store data. The client connects the primary node to the standby node at the same time and does not connect the quorum node.

By default, the master node provides all the additions and deletions, and the standby node does not provide any services. However, you can provide a query service by setting up the standby node, which can reduce the pressure on the primary node, and when the client makes a data query, the request is automatically forwarded to the standby node. This setting is called the Read Preference Modes, and the Java client provides a simple way to configure it without having to manipulate the database directly.

The quorum node is a special node that does not store data by itself, and the main purpose is to decide which standby node is promoted to the primary node after the master node is hung, so the client does not need to connect to this node. Although there is only one standby node, a quorum node is still required to raise the node level.

After the introduction of the cluster scheme, we now start building.

 1, download the three computers simultaneously, unzip the installation files

Download command:apt-get install MONGO

  2. Create MongoDB Data folder at the same time

    

    
1 mkdir-p/mongodb/data/master   2 mkdir-p/mongodb/data/slaver   3 mkdir-p/mongodb/data/arbiter    4 #三个目录分别对应主, standby, quorum node  
Create a Data folder

 3. Setting up the configuration file (M,s,a)

(i) Master node configuration file

    
1 #master. conf2dbpath=/mongodb/data/Master3logpath=/mongodb/log/Master.log4pidfilepath=/mongodb/Master.pid5directoryperdb=true  6Logappend=true  7replset=Testrs8bind_ip=10.10.148.130  9port=27017  TenOplogsize=10000   Onefork=true   ANoprealloc=true 
Master node configuration file

(ii) From the node configuration file

    
1 #slaver. conf2dbpath=/mongodb/data/slaver3logpath=/mongodb/log/Slaver.log4pidfilepath=/mongodb/Slaver.pid5directoryperdb=true  6Logappend=true  7replset=Testrs8bind_ip=10.10.148.131  9port=27017  TenOplogsize=10000   Onefork=true   ANoprealloc=true  
from the node configuration file

(iii) Quorum node configuration file

    
1 #arbiter. conf2dbpath=/mongodb/data/Arbiter3logpath=/mongodb/log/Arbiter.log4pidfilepath=/mongodb/Arbiter.pid5directoryperdb=true  6Logappend=true  7replset=Testrs8bind_ip=10.10.148.132  9port=27017  TenOplogsize=10000   Onefork=true   ANoprealloc=true  
Quorum node configuration file

  * parameter explanation in config file:

DBPath: Data Storage Directory

LogPath: Log Storage path

Pidfilepath: Process files, easy to stop MongoDB

Directoryperdb: Set up a folder for each database according to the database name

Logappend: Logging in Append mode

Replset:replica Set's name

IP address that is bound by Bind_ip:mongodb

The port number used by the PORT:MONGODB process, which defaults to 27017

Oplogsize:mongodb the maximum size of the operation log file. MB, default to 5% of the hard disk's remaining space

Fork: Run the process in the next stage mode

Noprealloc: No pre-allocated storage

  4, successively start Mongod or install MONGO service

  Go to the bin directory of each MongoDB node (change the configuration file path to the following command yourself)

  
./monood-f master.conf. /mongod-f slaver.conf.
View Code

  5. Configuration master, standby, quorum node

You can connect MongoDB via client, or you can choose a connection to mongodb directly from three nodes.

  
./mongo10.10.148.130:27017#ip和port是某个节点的地址>Use admin>cfg={_id:"Testrs", members:[{_id:0, Host:'10.10.148.130:27017', Priority:2}, {_id:1, Host:'10.10.148.131:27017', Priority:1}, {_id:2, Host:'10.10.148.132:27017', Arbiteronly:true}] }; >rs.initiate (CFG)
Configure master-slave

CFG can be arbitrary name, of course, it is best not to be mongodb keyword, conf,config can. The outermost _id represents the name of the replica set, and the members contain the address and priority of all nodes. The highest priority becomes the master node, the 10.10.148.130:27017 here. It is particularly important to note that there is a special configuration--arbiteronly:true for the quorum node. This must not be less, or the main standby mode will not be effective.

  6. Test configuration is successful

The configuration of the effective time according to the different machine configuration will be long and short, the configuration is good, basically in more than 10 seconds can be effective, and some configuration takes two minutes. If it takes effect, the Execute rs.status () command will see the following information:

  
{          "Set":"Testrs",          "Date": Isodate ("2013-01-05t02:44:43z"),          "MyState":1,          " Members" : [                  {                          "_id":0,                          "name":"10.10.148.130:27017",                          " Health":1,                          " State":1,                          "Statestr":"PRIMARY",                          "Uptime": $,                          "Optime": Timestamp (1357285565000,1),                          "optimedate": Isodate ("2013-01-04t07:46:05z"),                          " Self":true                  },                  {                          "_id":1,                          "name":"10.10.148.131:27017",                          " Health":1,                          " State":2,                          "Statestr":"Secondary",                          "Uptime": $,                          "Optime": Timestamp (1357285565000,1),                          "optimedate": Isodate ("2013-01-04t07:46:05z"),                          "lastheartbeat": Isodate ("2013-01-05t02:44:42z"),                          "Pingms":0                  },                  {                          "_id":2,                          "name":"10.10.148.132:27017",                          " Health":1,                          " State":7,                          "Statestr":"Arbiter",                          "Uptime": $,                          "lastheartbeat": Isodate ("2013-01-05t02:44:42z"),                          "Pingms":0                  }          ],          "OK":1  }  
Configuration Success Prompt

Configuring prompt: "Statestr": "RECOVERING"

Something:

   Replica Set is the main cluster I use now, and it's the most stable and efficient way to store irregular big data. Such a configuration requires at least three windows/ubuntu of the operating environment, of course, we can use VMS for virtualization testing, in the course of implementation of the project is also recommended to configure multiple servers, if the ability of course can be on virtual + storage. As for the data retrieval part of big data, tens the following use of the index of MongoDB can completely solve, over billion recommended to use the search platform, recent individuals in the research Elasticseach Big Data retrieval platform, if interested can learn together to learn ~ above is MongoDB the configuration process for Replica Set. A little toast!

MongoDB primary, secondary, quorum node cluster installation

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.