MongoDB advanced ---- & gt; MongoDB Auto-sharding

Source: Internet
Author: User

Skip the theoretical things and go to the web page to introduce automatic sharding.

Or test with million data

Insert million pieces of data to a database without sharding.

Data storage:

  1. Performance_^ [root @:/usr/local/mongodb/data/mongodb/test] # ls-lh
  2. Total 4.0 GB
  3. -Rw ------- 1 root 64 M Jul 25 :25 test.0
  4. -Rw ------- 1 root 128 M Jul 25 :22 test.1
  5. -Rw ------- 1 root 256 M Jul 25 :23 test.2
  6. -Rw ------- 1 root 512 M Jul 25 :25 test.3
  7. -Rw ------- 1 root 1.0G Jul 25 :25 test.4
  8. -Rw ------- 1 root 2.0G Jul 25 :24 test.5
  9. -Rw ------- 1 root 16 M Jul 25 :25 test. ns
Perform automatic sharding configuration as follows:

Here we select two servers for testing.

Test Machine IP Address:

10. X. X.163

10. X. X.228

Start the Shardsvr process on the 163,228 server.

  1. Pai_^ [root @:/usr/local/mongodb/bin] # cat runServerShard. sh
  2. ./Mongod -- shardsvr-dbpath = ../data/mongodb -- logpath = ../data/shardsvr_logs.txt -- logappend -- fork

Start the configsvr and mongos routing processes on the 163 server (the following 27019 is the ip address of configsvr, And the ip address of mongos can be viewed in the log)

  1. [Root @ localhost bin] # cat runServerConfig. sh
  2. ./Mongod -- configsvr -- dbpath = ../data/mongodb/config_db/-- logpath = ../data/mongodb/log/configsvr_logs.txt -- logappend -- fork
  3. [Root @ localhost bin] # cat runServerMongos. sh
  4. ./Mongos -- configdb 10.10.21.163: 27019 -- logpath = ../data/mongodb/log/s_s_logs.txt -- logappend -- fork
Check whether all startup is successful:
  1. [Root @ localhost bin] # ps-ef | grep'Mongo'
  2. Root 17939 1 2 :47? 00:01:26./mongod -- shardsvr-dbpath = ../data/mongodb -- logpath = ../data/shardsvr_logs.txt -- logappend -- fork
  3. Root 18250 1 0 :05? 00:00:00./mongod -- configsvr -- dbpath = ../data/mongodb/config_db/-- logpath = ../data/mongodb/log/configsvr_logs.txt -- logappend -- fork
  4. Root 18290 1 12 19: 08? 00:03:35./mongos -- configdb 10.10.21.163: 27019 -- logpath = ../data/mongodb/log/s_s_logs.txt -- logappend -- fork

It can be seen that all three services have been started successfully.

Configure Automatic parts as follows:

Use mongo to connect to the mongos process (see the log) for configuration management:

  1. > Use admin
  2. Switched to db admin
  3. > Db. runCommand ({addshard:"10.10.21.163: 27018"});
  4. {"OK": 0,"Errmsg":"Host already used"}
  5. > Db. runCommand ({addshard:"10.7.3.228: 27018"});
  6. {"ShardAdded":"Shard0001","OK": 1}
  7. > Db. runCommand ({enableSharding:"Test"})
  8. {"OK": 1}
  9. > Db. runCommand ({shardcollection:"Test. users", Key: {_ id: 1 }})
  10. {"Collectionsharded":"Test. users","OK": 1}

Insert million data into the mongos Process

Let's see the data size:

163:

  1. Pai_^ [root @:/usr/local/mongodb/data/mongodb] # ls-lh
  2. Total 2.0 GB
  3. -Rw-r -- 1 root 1011 Jul 25 :33 mongodb. log
  4. -Rwxr-xr-x 1 root 6 Jul 25 12:34 mongod. lock
  5. Drwxr-xr-x 3 root 4.0 K Jul 25 moveChunk
  6. -Rw ------- 1 root 64 M Jul 25 :42 test.0
  7. -Rw ------- 1 root 128 M Jul 25 :40 test.1
  8. -Rw ------- 1 root 256 M Jul 25 :41 test.2
  9. -Rw ------- 1 root 512 M Jul 25 12:42 test.3
  10. -Rw ------- 1 root 1.0G Jul 25 :41 test.4
  11. -Rw ------- 1 root 16 M Jul 25 :42 test. ns
  12. Drwxr-xr-x 2 root 4.0 K Jul 25 _ tmp
228:
  1. [Root @ localhost mongodb] # ls-lh
  2. Total 2.0 GB
  3. Drwxr-xr-x 3 root 4.0 K 07-25 19:39 config_db
  4. Drwxr-xr-x 2 root 4.0 K 07-25 18:51 config_repair_db
  5. Drwxr-xr-x 2 root 4.0 K 07-25 log
  6. -Rwxr-xr-x 1 root 6 07-25 19:39 mongod. lock
  7. Drwxr-xr-x 3 root 4.0 K 07-25 19: 13 movechun
  8. -Rw ------- 1 root 64 M 07-25 20:38 test.0
  9. -Rw ------- 1 root 128 M 07-25 20:38 test.1
  10. -Rw ------- 1 root 256 M 07-25 20:40 test.2
  11. -Rw ------- 1 root 512 M 07-25 20:41 test.3
  12. -Rw ------- 1 root 1.0G 07-25 20:42 test.4
  13. -Rw ------- 1 root 16 M 07-25 20:38 test. ns
  14. Drwxr-xr-x 2 root 4.0 K 07-25 20:38 _ tmp
Auto-sharding into every 2 GB.

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.