MongoDB's replica set replica set cluster build

Source: Internet
Author: User
Tags mongodb add

Experimental construction of a cluster to do practiced hand.

Configuration and Environment:

Win10 (native) and Linux (CENTOS7) intranet servers each.

Mongodb3.07

Target: Replica set replica set structure, a primary a slave, to achieve read-write separation of the synchronous data cluster.


First, native and intranet server installation MONGO

Refer to my other two articles:

MongoDB installation configuration on Windows and Linux platforms (http://fykknd.blog.51cto.com/3175618/1716343)

MongoDB Rights Management (http://fykknd.blog.51cto.com/3175618/1716369)

Second, cluster configuration

Before everything started, there was a preparation work, when the configuration of the cluster because this matter delayed for a long time, Baidu Google has no results, and finally asked an operation of a friend to know. is to do a key certification first!! Indicates that the machines between the clusters are mutually reliable.

Specific operation can refer to the official website description, at the end of the article has a link address.

# OpenSSL rand-base64 741 >/usr/local/mongodb/mongodb-keyfile# chmod 600/usr/local/mongodb/mongodb-keyfile

These two steps are to create a key file for use by the cluster machine. After the file is generated, copy the file to the corresponding directory of each member, and then start MONGO.

As a part of the cluster, start with a repl set parameter, which, like a team name, represents a member of the team. Write the start command first and then explain it.

# Mongod--config/etc/mongo.conf--dbpath=/usr/local/mongodb/data/--logpath=/usr/local/mongodb/logs/log.l--port= 27017--auth--fork--replset rs0--keyfile/usr/local/mongodb/mongodb-keyfile

This is the command line with the parameter mode start, you can also write the parameters in the mongo.conf. (My 3.07 version is extracted directly, by default there is no configuration file, you need to create a:/etc/mongo.conf) configuration file to see the Official document description (in the end of the article link), 2.6 after the document written in Yaml mode.

Parameter description:

--config Configuration file Location

--dbpath Data Storage Location

--logpath Log storage location

--port Port (can not be written)

--auth Start by authentication mode

--fork Background Run

--replset Replica set name

--keyfile secret key File location

Next configure the cluster config variable (remember to do the authentication operation, otherwise there is no permission to configure the cluster, I use the root user):

> config={_id: ' Dbset ', Members: [{_id:1, Host: ' 192.168.0.46 '}, {_id:2, Host: ' 192.168.0.207:27017 '}]}

After writing the config, initialize it:

> rs.initiate (config)


If everything works, you can use Rs.status () to view the status of the current cluster:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/76/77/wKioL1ZUE2XwQ54qAAA__mG3JXU242.png "title=" Rs.status "alt=" Wkiol1zue2xwq54qaaa__mg3jxu242.png "/>

Status Description:

1.STARTUP: Newly added to the replication set, the configuration is not yet loaded

2.STARTUP2: Configuration has finished loading, initialization state

3.RECOVERING: Recovering, not applicable to read

4.ARBITER: Arbitrator

5.DOWN: Node Unreachable

6.UNKNOWN: No other node state is acquired, but it is not known what state, generally occurs in only two members of the architecture, brain fissure

7.REMOVED: Remove a copy set

8.ROLLBACK: Data rollback at the end of rollback, transfer to recovering or secondary state

9.FATAL: Error. View Log grep "Replset FATAL" to find the wrong reason and redo the synchronization

10.PRIMARY: Master Node

11.SECONDARY: Backup Node


Add or remove nodes (need to be done on the master node):

Add Rs.addarb ("192.168.0.207");

Delete Rs.remove ("192.168.0.207");


In fact, it should also have a quorum node, but the current number of servers is not enough, so try to use another external network machine to do the next quorum node, and then encountered the configuration of modifying config problem. The answer on the Internet basically deleted the current settings to re-engage, in fact, there is a more convenient way to forcibly modify the config configuration (for example, I did not specify the priority parameter in config, the value is a cosmetic.) The larger the value, the higher the priority becomes the primary node. The premise is that the configuration file does not specify who is the primary node, and there is no--master parameter in the startup parameter). For example, the new config is:

> config={_id: ' Dbset ', Members: [{_id:1, host:192.168.0.46, priority:1}, {_id:2, host:192.168.0.207:27017, priority:0}]}

At this point, Rs.initiate (config) is invalid and needs to be performed:

> rs.reconfig (config);

So how do you add a quorum node? It's simple: Add a node to config and write arbiteronly:true on the back. For example: {_id:3, Host: "192.168.0.207:27018", arbiteronly:true}, and then reconfig again. However I did not succeed because I started on 207 on two different port simulations, but did not succeed. Attachment affixed with the error message, which big God pointed out the next mistake? Appreciate!


In addition, you can view the cluster configuration: rs.conf ();

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/76/77/wKioL1ZUFTrSzY3VAAAxHyPioE4357.png "title=" Rs.conf "alt=" Wkiol1zuftrszy3vaaaxhypioe4357.png "/>


Note: This article is the main reference source

mongoDB3.0.3 above GUI connection authentication problem http://www.bubuko.com/infodetail-984255.html

MongoDB 3.0 Security access Control http://blog.csdn.net/gsying1474/article/details/47813059

A brief analysis of MONGODB user management http://www.jb51.net/article/53830.htm

MONGO official website-key certification: https://docs.mongodb.org/manual/tutorial/enable-internal-authentication/

MONGO official website-configuration file notation: https://docs.mongodb.org/manual/reference/configuration-options/

MongoDB enforces one member as main: http://www.361way.com/mongodb-forced-primary/1704.html

MongoDB Add, remove Arbiter node instances: http://www.jb51.net/article/59597.htm

This article is from the "Technology Growth drip" blog, please be sure to keep this source http://fykknd.blog.51cto.com/3175618/1716409

MongoDB's replica set replica set cluster build

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.