Steps for MongoDB-based Distributed Data Storage

Source: Internet
Author: User

This article is a by-product study of Mongodb distributed data storage. Through the relevant steps in this article, we can distribute data in a large table to several mongo servers.

In MongoDB 1.6, the auto-sharding function is basically stable and can be used in a production environment. Because it is auto-sharding, mongodb uses mongos (an automatic sharding module used to build a large-scale scalable database cluster, which can be incorporated into dynamically increasing machines) A horizontally scalable Database Cluster System is automatically created to store database sub-tables on each sharding node.

A mongodb cluster includes some shards (including some mongod processes), mongos routing processes, and one or more config servers.

(Note: The test cases in this article require a 64-bit mongo program, because I have never succeeded in a 32-bit mongo program ).

The following are some vocabulary descriptions:

Shards: each shard includes one or more services and mongod processes that store data (mongod is the core process of MongoDB data). Typically, each shard enables multiple services to improve service availability. These service/mongod processes form a replica set in the shard.

Chunks: a Chunk is a data range from a special set. (collection, minKey, maxKey) describes a chunk, which is between minKey and maxKey. For example, the maxsize of chunks is 100 mb. If a file reaches or exceeds this range, it is split into two new chunks. When a shard has an excessive amount of data, chunks will be migrated to other shards. Similarly, chunks can be migrated to other shards.

Config Servers: The Config server stores the metadata information of the cluster, including the basic information and chunk information of each server and shard. The Config server stores the chunk information. Each config server copies the complete chunk information.

Next, let's take a look at the test environment information to be configured:

Simulate two shard services and one config service, all of which run on the 10.0.4.85 machine, but the ports are different:

Shard1: 27020

Shard2: 27021

Configuration: 27022

Default port 27017 used when Mongos is started

Create the following folders on disks C, D, and E:

Mongodb \ bin

Mongodb \ db

Then run the CMD command to open the mongd file in the corresponding folder in sequence:

C: \ Mongodb \ Bin \ Mongod -- Dbpath c: \ Mongodb \ Db \ -- Port 27020

D: \ Mongodb \ Bin \ Mongod -- Dbpath d: \ Mongodb \ Db \ -- Port 27021

E: \ Mongodb \ Bin \ Mongod -- Configsvr -- Dbpath e: \ Mongodb \ Db \ -- Port 27022

(Note: config configuration server)

When mongos is started, port 27017 is enabled by default:

E: \ Mongodb \ Bin \ Mongos -- Configdb 10.0 . 4.85 : 27022

Then open mongo:

E: \ mongodb \ bin> mongo press enter (sometimes adding a port causes the following addshard command to fail)

   > Use admin

Switched To Db admin

   > Db. runCommand ({addshard: " 10.0.4.85: 27020 " , AllowLocal: 1 , MaxSize: 2 , MinKey: 1 , MaxKey: 10 })

   -- Add a sharding. The maxsize unit is M. Here, a small value is set to only demonstrate the sharding effect.

{ " ShardAdded " : " Shard0000 " , " OK " : 1 }

   > Db. runCommand ({addshard: " 10.0.4.85: 27021 " , AllowLocal: 1 , MinKey: 1000 })

{ " ShardAdded " : " Shard0001 " , " OK " : 1 }

Note: To remove sharding, use the following method:

Db. runCommand ({removeshard: "localhost: 10000 "});

> Db. runCommand ({listshards: 1}); view the shard node list

Code highlighting produced By Actipro CodeHighlighter (freeware) http: // Www.CodeHighlighter.com / -- > {
"Shards ": [
{
"_ Id": "shard0000 ",
"Host": "10.0.4.85: 27020"
},
{
"_ Id": "shard0001 ",
"Host": "10.0.4.85: 27021"
}
] ,
"OK ": 1
}
  • 1
  • 2
  • 3
  • 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: 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.