MongoDB Cluster Scenario: Installation configuration for Replica set cluster

Source: Internet
Author: User
Tags mongodb
Overview

The MONGODB environment mainly includes standalone,replication and sharding. StandAlone: Stand-alone environment, the general development of the test when used. Replication: Master-slave structure, a primary, multiple secondary, there may be arbitry.
After the primary is hung up, a secondary will be elected as primary, similar to zookeeper. Arbitry does not save data, just for dine. The election algorithm requires that the number of nodes must be odd number, if primary+secondary is not an odd number, it is necessary to use Arbitry dine. Write data can only be primary, read the data by default also in primary, can be configured to read from secondary, you can select the nearest node. After the data is written successfully on the primary, the action is recorded in the Oplog, the secondary copies the Oplog, and then the data is done. Primary and secondary the data above guarantee final consistency, you can configure write concern for writes, there are several levels: write on primary to think that writing is successful, write to the oplog after writing success; write to one/more/one/ After a few secondary think write success, and so on. Sharding:share the structure of nothing, with only a fraction of the data per machine. Mongod Server storage data, MONGOs server is responsible for routing read and write requests, the metadata exists in the config database.
Because of the amount of data and the number of machines, the project ended up with a primary, a secondary, a arbitry. My own development environment is Ubuntu, and the test environment is CentOS. The 64-bit MongoDB is installed. Download, decompression Download mongodb-linux-x86_64-rhel62-3.4.10.tgz.gz decompression:

#解压命令
TAR-XZVF mongodb-linux-x86_64-rhel62-3.4.10.tgz.gz
Create and edit a configuration fileThe configuration files that are MongoDB to create mongod.conf based on the directory are as follows:
#mongod. conf path is: MongoDB extract directory/mongod.conf
Net:
  #bindIp: 127.0.0.1
  port:27017
systemlog:
  Destination:file
  Path:/app/mongodata/log/mongo.log
  logappend:true
storage: DBPath
  :/app/ Mongodata/data
processmanagement:
  fork:true
#security:
#  authorization:enabled
Replication:
   oplogsizemb:1024
   replsetname:rs-test
the other three are also configured, and then start each
#启动命令
mongod-f mongod.conf
Initializing clusters
# 1, select a MongoDB service, through the Bin/mongo command for console
Bin/mongo
# 2, switch to admin library use
admin
# 3, define initialization configuration
config={"_id": "Rs-test", "members": [{"_id": 0, "host": "mongodb-node1:27017"}, {"_id": 1, "host": "Mongodb-nod e2:27017 "}, {" _id ": 2," host ":" MONGODB-NODE3:27017 "}]}
# 4, initialize
rs.initiate (config);
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.