Research on Auto-sharding

Source: Internet
Author: User

Skip the theory. I have introduced automatic sharding on the internet... directly go to the configuration. Please leave a message if you have any questions.

Or test with million data

Insert million pieces of data to a database without sharding.

Data storage:

 
 
  1. ^_^[root@:/usr/local/mongodb/data/mongodb/test]#ls -lh 
  2. total 4.0G 
  3. -rw------- 1 root root  64M Jul 25 11:25 test.0 
  4. -rw------- 1 root root 128M Jul 25 11:22 test.1 
  5. -rw------- 1 root root 256M Jul 25 11:23 test.2 
  6. -rw------- 1 root root 512M Jul 25 11:25 test.3 
  7. -rw------- 1 root root 1.0G Jul 25 11:25 test.4 
  8. -rw------- 1 root root 2.0G Jul 25 11:24 test.5 
  9. -rw------- 1 root root  16M Jul 25 11: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. ^_^[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/mongos_logs.txt --logappend --fork 

Check whether all startup is successful:

 
 
  1. [root@localhost bin]# ps -ef | grep 'mongo' 
  2. root     17939     1  2 18:47 ?        00:01:26 ./mongod --shardsvr -dbpath=../data/mongodb --logpath=../data/shardsvr_logs.txt --logappend --fork 
  3. root     18250     1  0 19: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/mongos_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. ^_^[root@:/usr/local/mongodb/data/mongodb]#ls -lh 
  2. total 2.0G 
  3. -rw-r--r-- 1 root root 1011 Jul 25 12:33 mongodb.log 
  4. -rwxr-xr-x 1 root root    6 Jul 25 12:34 mongod.lock 
  5. drwxr-xr-x 3 root root 4.0K Jul 25 12:39 moveChunk 
  6. -rw------- 1 root root  64M Jul 25 12:42 test.0 
  7. -rw------- 1 root root 128M Jul 25 12:40 test.1 
  8. -rw------- 1 root root 256M Jul 25 12:41 test.2 
  9. -rw------- 1 root root 512M Jul 25 12:42 test.3 
  10. -rw------- 1 root root 1.0G Jul 25 12:41 test.4 
  11. -rw------- 1 root root  16M Jul 25 12:42 test.ns 
  12. drwxr-xr-x 2 root root 4.0K Jul 25 12:38 _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 moveChunk
  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.