Create a MongoDB Cluster

Source: Internet
Author: User
Tags connect mongo

A cluster consists of the following three services:

  1. Shards server: each shard is composed of one or more mongod processes used to store data.
  2. Config server: used to store the metadata information of a cluster, including the information of each shard and chunks.
  3. Route server: used to provide the routing service, connected by the client, so that the entire cluster looks like a single DB Server

In addition, chunks are continuous data blocks in MongoDB. The default size is 200 MB, and a chunk is located on one of the shard servers.

Next, build a cluster, which consists of four servers, including two Shard, three config, and one route

Each Shard is composed of a replica set, and each replica set is composed of two mongod nodes and one vote node.

Directory/opt/soft/MongoDB/data,/opt/soft/MongoDB/log

192.168.11.229
/Opt/soft/MongoDB/bin/mongod-fork-shardsvr-port 10000-replset set1-dbpath/opt/soft/MongoDB/data-logpath/opt/soft/MongoDB /log. log
/Opt/soft/MongoDB/bin/mongod-fork-shardsvr-port 10001-replset set2-dbpath/opt/soft/MongoDB/data/data1-logpath/opt/soft/MongoDB /log/log1.log
192.168.11.17
/Usr/local/MongoDB/bin/mongod-fork-shardsvr-port 10000-replset set1-dbpath/opt/soft/MongoDB/data-logpath/pvdata/mongodb_log/mongod. log
192.168.11.227
/Usr/local/MongoDB/bin/mongod-fork-shardsvr-port 10000-replset set2-dbpath/opt/soft/MongoDB/data-logpath/opt/soft/MongoDB /log/mongod. log
/Usr/local/MongoDB/bin/mongod-fork-shardsvr-port 10001-replset set1-dbpath/opt/soft/MongoDB/data/data1-logpath/opt/soft/MongoDB /log/mongod1.log

192.168.11.228
/Usr/local/MongoDB/bin/mongod-fork-shardsvr-port 10000-replset set2-dbpath/opt/soft/MongoDB/data-logpath/opt/soft/MongoDB /log/mongod. log

 

Connect mongo-port 10000 to Mongo on 192.168.11.229

Config = {_ ID: 'set1', members :[
{_ ID: 0, host: '192. 168.11.229: 100 '},
{_ ID: 1, host: '192. 168.11.17: 100 '},
{_ ID: 2, host: '192. 168.11.227: 100', arbiteronly: true}
]}
Rs. Initiate (config)
Rs. Status ()

Connect mongo-port 10000 to Mongo on 192.168.11.227
Config = {_ ID: 'set2', members :[
{_ ID: 0, host: '192. 168.11.227: 100 '},
{_ ID: 1, host: '192. 168.11.228: 100 '},
{_ ID: 2, host: '192. 168.11.229: 100', arbiteronly: true}
]}
Rs. Initiate (config)
Rs. Status ()

 

192.168.11.229:; 192.168.11.17; start the process on 192.168.11.228
Mongod -- configsvr -- fork -- logpath/opt/soft/MongoDB/log/config. log -- logappend -- dbpath/opt/soft/MongoDB/data/configdata -- port 20000

 

Start the process on 192.168.11.227

Mongos -- fork -- configdb "192.168.11.229: 20000,192.168 .11.17: 20000,192.168 .11.228: 20000" -- logpath/opt/soft/MongoDB/log/mongos. Log

 

192.168.11.227

Mongos> Use Admin
Mongos> dB. admincommand ({addshard: "set1/192.168.20.29: 10000,192.168 .11.17: 10000 "})
Mongos> dB. admincommand ({addshard: "set2/192.168.11.227: 10000,192.168 .11.228: 10000 "})
Mongos> dB. admincommand ({enablesharding: 'test '})
Mongos> dB. admincommand ({listshards: 1 })
Mongos> printshardingstatus ()
Mongos> dB. admincommand ({shardcollection: 'test. test2', key: {_ ID: 1}, unique: true })

 

Import text data (separated by commas)

Export Import-H 192.168.11.227-d test-C test -- type CSV-f ip, Sid, uid, cateid, type -- file/opt/dm/META/uidip_20111017

 

 

 

 

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.