MongoDB Sharding Learning Operation Chapter

Source: Internet
Author: User
Tags mongodb sharding mongodb version

The MongoDB version used in this article is 2.4.6, which uses the following deployment architecture for testing and not for the online environment. The following tests are all done on this machine, and the on-line environment requires separate deployment for each component.

650) this.width=650; "Src=" Http://docs.mongodb.org/manual/_images/sharded-cluster-production-architecture.png " alt= "Diagram of a sample sharded cluster for production purposes. Contains exactly 3 config servers, 2 or more "MONGOs" query routers, and at least 2 shards. The shards is replica sets. "/>


1. Add Host List

Vim/etc/hosts Add the following list

127.0.0.1 mongo-sharding-router1127.0.0.1 mongo-sharding-router2127.0.0.1 mongo-sharding-config1127.0.0.1  mongo-sharding-config2127.0.0.1 mongo-sharding-config3127.0.0.1 mongo-sharding-replica1127.0.0.1  mongo-sharding-replica2127.0.0.1 mongo-sharding-replica3127.0.0.1 mongo-sharding-replica4127.0.0.1 mongo-sharding-replica5127.0.0.1 MONGO-SHARDING-REPLICA6


2. Configure two Shard, each with three member replica Set

The corresponding host list

Shard1

127.0.0.1 MONGO-SHARDING-REPLICA1 2811 Primary127.0.0.1 mongo-sharding-replica2 2822 secon dary127.0.0.1 MONGO-SHARDING-REPLICA3 2833 Secondary


Shard2

127.0.0.1 mongo-sharding-replica4 3811 Primary127.0.0.1 mongo-sharding-replica5 3822 secon dary127.0.0.1 mongo-sharding-replica6 3833 Secondary


The deployment architecture is as follows:

650) this.width=650; "Src=" http://docs.mongodb.org/v2.4/_images/ Replica-set-primary-with-secondary-and-arbiter.png "alt=" Diagram of a replica set that consists of a primary, a secondary, and an arbiter. "/>

A. Configure the MONGO-SHARDING-REPLICA1,MONGO-SHARDING-REPLICA2 and MONGO-SHARDING-REPLICA3 MongoDB configuration files and startup scripts separately and start MongoDB

such as MONGO-SHARDING-REPLICA1 related configuration

# cat/etc/mongod2811.conf Logpath=/data/app_data/mongodb/log2811/mongodb.log logappend=truefork=trueport= 2811dbpath=/data/app_data/mongodb/data2811/pidfilepath=/data/app_data/mongodb/data2811/mongod.pidmaxconns= 2048nohttpinterface=truedirectoryperdb=truereplset=test_shard1


/etc/init.d/mongod2811

#!/bin/bash# mongod - startup script for mongod# chkconfig: 35 85  15# description: mongo is a scalable, document-oriented database.#  processname: mongod# config: /etc/mongod.conf# pidfile: /data/app_data/mongodb/ Data/mongodb/mongod.pid. /etc/rc.d/init.d/functions# things from mongod.conf get  there by mongod reading it# NOTE: if you change any  Options here, you get what you pay for:# this script assumes  all options are in the config file. Configfile= "/etc/mongod2811.conf" options= " -f  $CONFIGFILE" sysconfig= "/etc/sysconfig/mongod" #  fixme: 1.9.x has a --shutdown flag that parses the config  file and# shuts down the correct Running pid, but that ' S unavailable in 1.8# for now.  this  can go away when this script stops supporting 1.8.dbpath= ' awk  -F=  '/^dbpath=/{print $2} '   "$CONFIGFILE" ' pidfile= ' awk -f=  '/^pidfilepath=/{ print $2} '   "$CONFIGFILE" ' mongod=${mongod-/data/app_platform/mongodb/bin/mongod}mongo_user= mongodmongo_group=mongodif [ -f  "$SYSCONFIG"  ]; then    .  "$ SYSCONFIG "fi# handle numa access to cpus  (SERVER-3574) # this verifies  the existence of numactl as well as testing that the  command worksnumactl_args= "--interleave=all" if which numactl >/dev/null 2>/dev/ null && numactl  $NUMACTL _args ls / >/dev/null 2>/dev/nullthen     numactl= "numactl  $NUMACTL _args" else    numactl= "" Fistart () {  echo -n $ " starting mongod:    daemon --user  $MONGO _user   $NUMACTL   $mongod   $OPTIONS   RETVAL=$?  echo  [  $RETVAL  -eq 0 ] &&  touch /var/lock/subsys/mongod}stop () {  echo -n $ "Stopping mongod: "   killproc -p  "$PIDFILE"  -d 300 /data/app_platform/mongodb/bin/mongod   RETVAL=$?  echo  [  $RETVAL  -eq 0 ] && rm  -f /var/lock/subsys/mongod}restart  ()  {    stop     start}ulimit -n 12000retval=0case  "$"  in  start)     start     ;;   stop)     stop    ;;   restart|reload|force-reload)     restart    ;;   condrestart)     [ -f /var/lock/subsys/mongod ] &&  restart | |  :    ;;   status)     status  $mongod     RETVAL=$?     ;;   *)     echo  "usage: $0 {start|stop|status|restart|reload| Force-reload|condrestart} "    RETVAL=1esacexit  $RETVAL


Note/data/app_data/mongodb/The permissions setting for this directory becomes the user right for the Mongod process to run.

# service mongod2811 startstarting mongod: about to fork child  Process, waiting until server is ready for connections.all output  going to: /data/app_data/mongodb/log2811/mongodb.logforked process: 4589child  process started successfully, parent exiting                                                              [   Ok  ]# service mongod2822 startstarting mongod: about to fork  child process, waiting until server is ready for connections.all  output going to:  /data/app_data/mongodb/log2822/mongodb.logforked process: 4656child process started  successfully, parent exiting                                                              [  OK  ]#  Service mongod2833 startstarting mongod: about to fork child process,  waiting until server is ready for connections.all output going  to: /data/app_data/mongodb/log2833/mongodb.logforked process: 4723child process  started successfully, parent exiting                                                              [  OK  ]


B. Initialize Replica Set

# /data/app_platform/mongodb/bin/mongo   --port 2811mongodb shell version:  2.4.6connecting to: 127.0.0.1:2811/test> rs.status (); {"Startupstatus"  : 3, "info"  :  "run rs.initiate (...)"  if not yet done for the set "," OK " : 0," errmsg " : " can " t get local.system.replset config from self or any seed  ( Emptyconfig) "}> rs.initiate (" mongo-sharding-replica1:2811 "); {"Info2"  :  "No configuration explicitly specified -- making one", "Me"  :  "mongo-sharding-replica1:2811", "info"  :  "config now saved locally.   should come online in about a minute. "," OK " : 1}> test_ Shard1:primary> test_shard1:primary> rs.status (); {"Set"  :  "Test_shard1", "Date"  : isodate ("2015-01-07t10:16:51z ")," MyState " : 1," members " : [{" _id " : 0," name " : " mongo-sharding-replica1:2811 "," Health " : 1," state " : 1," Statestr " : " PRIMARY "," Uptime " : 569," Optime " : timestamp (1420625715, 1)," Optimedate " : isodate (" 2015-01-07t10:15:15z ")," Self " : true}]," OK " : 1}


C. Adding MONGO-SHARDING-REPLICA2 and MONGO-SHARDING-REPLICA3 to the replica set

Test_shard1:primary> Rs.add ("mongo-sharding-replica2:2822"); {"OK": 1}test_shard1:primary> rs.add ("mongo-sharding-replica3:2833"); {"OK": 1}test_shard1:primary> rs.config (); {"_id": "Test_shard1", "Version": 5, "members": [{"_id": 0, "host": "mongo-sharding-replica1:2811"},{"_id": 1, "host": "mongo-sharding-replica2:2822"},{"_id": 2, "host": "mongo-sharding-replica3:2833"}]}test_shard1:primary>


D. Viewing the status of mongo-sharding-replica2:2822 and mongo-sharding-replica3:2833

# /data/app_platform/mongodb/bin/mongo --port  2822mongodb shell version: 2.4.6connecting to: 127.0.0.1:2822/testtest_shard1: Secondary> db.ismaster (); {"SetName"  :  "Test_shard1", "IsMaster"  : false, "secondary"  : true, "hosts"  :  ["mongo-sharding-replica2:2822", "mongo-sharding-replica3:2833", "mongo-sharding-replica1:2811"], "primary"  :  "mongo-sharding-replica1:2811", "Me"  :  "mongo-sharding-replica2:2822", "maxbsonobjectsize " : 16777216," Maxmessagesizebytes " : 48000000," localtime " : isodate (" 2015-01-07t10:21:41.522z ")," OK " : 1}TEST_SHARD1:SECONDARY> 
#/data/app_platform/mongodb/bin/mongo--port 2833MongoDB Shell version:2.4.6connecting to:127.0.0.1:2833/testtest_ Shard1:secondary> Db.ismaster (); {"SetName": "Test_shard1", "IsMaster": false, "secondary": True, "hosts": ["mongo-sharding-replica3:2833", " mongo-sharding-replica2:2822 "," mongo-sharding-replica1:2811 "]," PRIMARY ":" mongo-sharding-replica1:2811 "," Me ":" mongo-sharding-replica3:2833 "," maxbsonobjectsize ": 16777216," maxmessagesizebytes ": 48000000," LocalTime ": ISODate ( "2015-01-07t10:22:27.125z"), "OK": 1}test_shard1:secondary>


Similarly, the same configuration for Shard2 MongoDB instances



3. Configure Config server



Reference article:

http://docs.mongodb.org/manual/administration/sharded-cluster-deployment/


This article is from the Linux SA John blog, so be sure to keep this source http://john88wang.blog.51cto.com/2165294/1600189

MongoDB Sharding Learning Operation Chapter

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.