MongoDB Shard Deployment

Source: Internet
Author: User

Mongodb Shard Deployment

Configure a MongoDB cluster, such as a MongoDB cluster with 3 shard configured on 3 servers:

Architecture:

1. Each piece of data requires 3 Mongod server,2 primary from the data node, 1 is the quorum node (arbiter), and no data is stored. Altogether three pieces, can be made:

   20.220-mongo1:   20001(SH1 master),20002(Sh2 from),20003(SH3 arbitration)      20.221-mongo2:   20002(SH2 master),20003(SH3 from),20001(SH1 arbitration)     20.222-mongo3:   20003(SH3 master),20001(SH1),20002

2. Requires 3 mongod config server, log in 3 machines to perform the following

 20.220 -mongo1: 19999   echo   "  " >>/etc/profiletar ZXVF MongoDB -linux-x86_64-2.6 . 0  .tgzmv mongodb -linux-x86_64-0 /usr/local/mongodbmkdir -p/usr/local/mongodb/{ETC,DATE,LOG}CD /usr/local/mongodb/datemkdir Sh1mkdir sh2mkdir Sh3mkdir Cf1mkdir Cf2mkdir CF3  
 20.221 -mongo2: 19998   echo   "  " >>/etc/profiletar ZXVF MongoDB -linux-x86_64-2.6 . 0  .tgzmv mongodb -linux-x86_64-0 /usr/local/mongodbmkdir -p/usr/local/mongodb/{ETC,DATE,LOG}CD /usr/local/mongodb/datemkdir Sh1mkdir sh2mkdir Sh3mkdir Cf1mkdir Cf2mkdir CF3  
20.222 19997 ' Export path= $PATH:/usr/local/mongodb/bin' >>/etc/profiletar       ZXVF MongoDB-linux-x86_64-2.6. 0 . TGZMV MongoDB-linux-x86_64-2.6. 0 /usr/local/-p/usr/local/mongodb//usr/local/mongodb/datemkdir sh1mkdir Sh2mkdir sh3mkdir cf1mkdir cf2mkdir cf3

3. MONGOs server as a portal

192.168. 20.220 20000

1. Start Mongod Datanode Service

40000 20001 40000 20002 40000 20003

2. Configure each piece of replica set, that is, each 3 units with a replica set mutual preparation

20.220-192.168. 20.220:20001/adminuse admin;
 config = {_id:  " sh1   '   
// Initialize REPL set

Rs.status ()   // See if the results have been successfully completed REPL set

20.221-192.168. 20.221:20002/adminuse admin;
 config = {_id:  " sh2   '   
// Initialize REPL set

Rs.status ()   // See if the results have been successfully completed REPL set

20.222-192.168. 20.222:20003/
 config = {_id:  " sh3   '   
// Initialize REPL set

Rs.status ()   // See if the results have been successfully completed REPL set

3. Execute Start config server:

19999 --dbpath/usr/local/mongodb/date/cf1/--logpath/usr/local/mongodb/log/cf1.log20.221 -mongo219998 --dbpath/usr/local/mongodb/date/cf2/--logpath/usr/local/mongodb/log/  Cf2.log20.222-mongo319997

4. Start MONGOs Server

192.168. 20.220:19999,192.168. 20.221:19998,192.168. 20.222:1999720000

5. Configuring the MONGO Shard Cluster

192.168. 20.220:20000/admin
Mongos> Db.runcommand ({addshard:"sh1/192.168.20.220:20001,192.168.20.221:20001", Name:"sh1"});

Mongos> Db.runcommand ({addshard:"sh2/192.168.20.221:20002,192.168.20.222:20002", Name:"sh2"});

Mongos> Db.runcommand ({addshard:"sh3/192.168.20.222:20003,192.168.20.220:20003", Name:"sh3"});

Mongos> Db.runcommand ({listshards:1})

6. Activating database Shards

Login MONGOs:

>use admin;
" dbname " } );

>db.runcommand ({shardcollection: "Dbname.collectionname", key: {"Keyfield": 1}});

Note the Keyfield required for sharding is the table index.

Sh.enablesharding ("dbname")

MongoDB Shard Deployment

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.