MongoDB cluster in Linux-replica set Environment Construction

Source: Internet
Author: User
Tags install mongodb

MongoDB cluster in Linux-replica set Environment Construction

MongoDB replica sets are suitable for scenarios with fewer writes and more reads. You can use message queues for write control to reduce the pressure on highly concurrent writes. The Application Scenario of replica set should be selected based on the project requirements. If there is a high concurrency write requirement, we recommend that you build a cluster using sharding mode, which is higher than the replica set in terms of stability. My application scenario here is to use queue control for write operations, mainly for queries.

After the master node fails in the replica set and is detected by the heartbeat mechanism, the master node election mechanism is initiated in the cluster to automatically elect a new master server.

After the master node fails, automatic failover is performed. The number of nodes must be greater than or equal to 3. Otherwise, a primary election error may occur. The official recommendation is an odd number of nodes. I will use three nodes here.

Install mongoDB on each node

Mkdir/data/mongo/replset
# Store mongodb data files
Mkdir-p/data/mongo/replset/data
# Go To The mongodb folder
Cd/data/mongo
Download to deployment package
Wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.12.tar
Tar xzvf mongodb-linux-x86_64-2.4.12.tar
Next, run the following command on each machine:
/Data/mongo/mongodb-linux-x86_64-2.4.12/bin/mongod -- fork -- dbpath/data/mongo/replset/data -- logpath =/data/mongo/logs/logs.info -- replSet repset
Note: It is started in the background, and the fork must be added.
Log on to mongodb on any of the three machines
// Data/mongo/mongodb-linux-x86_64-2.4.12/bin/mongo
Use admin
Define replica set configuration variables
Config = {_ id: "repset ",
Members :[
{_ Id: 0, host: "x. x. x.8: 27017 "},
{_ Id: 1, host: "x. x. x.9: 27017 "},
{_ Id: 2, host: "x. x. x.10: 27017 "}
]}

After successful configuration

Initialize replica set
Rs. initiate (config );

View cluster node status
Rs. status ();

Test whether the replica set is synchronized.
Log on to the master node
/Data/mongo/mongodb-linux-x86_64-2.4.12/bin/mongo 127.0.0.1 or local node IP
Create a Test Database
Use test;

Db. testdb. insert ({"demo": "demo "})
Go to another replica machine and check that the data has been synchronized.

You can stop the master node and check the effect of automatic master selection.

CentOS compilation and installation of MongoDB

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.