MongoDB AutoSharding + Replication sets Stability Test

Source: Internet
Author: User

Single Replication sets design:

, 10.9.3.228, only Mongos and config services are started.

 
 
  1. ^_^[root@:/usr/local/mongodb/bin]#cat runServerConfig.sh  
  2. ./mongod --configsvr --dbpath=../data/config --logpath=../data/config.log --fork  
  3. ^_^[root@:/usr/local/mongodb/bin]#cat runServerMongos.sh  
  4. ./mongos --configdb 10.7.3.228:27019 --logpath=../data/mongos.log --logappend --fork 

Note: The ip addresses and ports in Mongos are the ip addresses and ports of the config service.

Advanced Configuration AutoSharding

163 of shardv has been started, as long as the autoSharding service of the 165 server is started

 
 
  1. [root@localhost bin]# cat runServerShard.sh    
  2. ./mongod --shardsvr -dbpath=../data/mongodb --logpath=../data/shardsvr_logs.txt --fork 

Configure the Sharding on the 228 server.

Use admin

 
 
  1. > db.runCommand({addshard:"10.10.21.163:27018"});    
  2. { "shardAdded" : "shard0000", "ok" : 1 }   
  3. > db.runCommand({addshard:"10.10.21.165:27018"});    
  4. { "shardAdded" : "shard0001", "ok" : 1 }   
  5. > db.runCommand({enableSharding:"test"})     
  6. { "ok" : 1 }   
 
 
  1. > db.runCommand({shardcollection:"test.users",key:{_id:1}})     
  2. { "collectionsharded" : "test.users", "ok" : 1 }   

Then, start the rep service on the 163 and 164 servers respectively, and the 163 server should start the shard service separately.

163:

 
 
  1. [root@localhost bin]# cat runServerShard.sh    
  2. ./mongod --shardsvr --dbpath=../data/mongodb --logpath=../data/shardsvr_logs.txt --fork --replSet set163164   

164:

 
 
  1. [root@localhost bin]# cat runServerShard.sh    
  2. ./mongod --dbpath=../data --logpath=../data/shardsvr_logs.txt --fork --replSet set163164   

Continue to configure Replication for 163 and 164

 
 
  1. [root@localhost bin]# ./mongo 10.10.21.163:27018   
  2. MongoDB shell version: 1.8.2   
  3. connecting to: 10.10.21.163:27018/test   
  4. > cfg={_id:"set163164",members:[                               
  5. ... {_id:0,host:"10.10.21.163:27018"},   
  6. ... {_id:1,host:"10.10.21.164:27017"}   
  7. ... ]}   
  8. {   
  9.         "_id" : "set163164",   
  10.         "members" : [   
  11.                 {   
  12.                         "_id" : 0,   
  13.                         "host" : "10.10.21.163:27018"   
  14.                 },   
  15.                 {   
  16.                         "_id" : 1,   
  17.                         "host" : "10.10.21.164:27017"   
  18.                 }   
  19.         ]   
  20. }   
  21. > rs.initiate(cfg)   
  22. {   
  23.         "info" : "Config now saved locally.  Should come online in about a minute.",   
  24.         "ok" : 1   
  25. }   
  26. > rs.conf()   
  27. {   
  28.         "_id" : "set163164",   
  29.         "version" : 1,   
  30.         "members" : [   
  31.                 {   
  32.                         "_id" : 0,   
  33.                         "host" : "10.10.21.163:27018"   
  34.                 },   
  35.                 {   
  36.                         "_id" : 1,   
  37.                         "host" : "10.10.21.164:27017"   
  38.                 }   
  39.         ]   
  40. }   
  41. set163164:PRIMARY>    
  42. set163164:PRIMARY>    
  43. set163164:PRIMARY> show dbs   
  44. admin   (empty)   
  45. local   14.1962890625GB   
  46. set163164:PRIMARY> use local   
  47. switched to db local   
  48. set163164:PRIMARY> show collections   
  49. oplog.rs   
  50. system.replset   
  51. set163164:PRIMARY> db.system.replset.find()   
  52. { "_id" : "set163164", "version" : 1, "members" : [   
  53.         {   
  54.                 "_id" : 0,   
  55.                 "host" : "10.10.21.163:27018"   
  56.         },   
  57.         {   
  58.                 "_id" : 1,   
  59.                 "host" : "10.10.21.164:27017"   
  60.         }   
  61. ] }   
  62. set163164:PRIMARY> rs.isMaster()   
  63. {   
  64.         "setName" : "set163164",   
  65.         "ismaster" : true,   
  66.         "secondary" : false,   
  67.         "hosts" : [   
  68.                 "10.10.21.163:27018",   
  69.                 "10.10.21.164:27017"   
  70.         ],   
  71.         "maxBsonObjectSize" : 16777216,   
  72.         "ok" : 1   
  73. }   

So far, Replication sets are configured successfully!

So far, AutoSharding + Rep is successfully configured. Then perform the stability test. (You should configure sharding before Replication)

First look at the result:

We can see that a total of 163 pieces of data are inserted, and 164 and 165 of the same size are part data.

I am now conducting a stability test:

163 servers are disconnected.

Mongos then query accordingly:

 
 
  1. > db.users.find()   
  2. error: { "$err" : "error querying server: 10.10.21.163:27018", "code" : 13633 }   
  3. > db.users.find()   
  4. error: {   
  5.         "$err" : "DBClientBase::findOne: transport error: 10.10.21.163:27018 query: { setShardVersion: \"test.users\", configdb: \"10.7.3.228:27019\", version: Timestamp 11000|1, serverID: ObjectId('4e2f64af98dd90fed26585a4'), shard: \"shard0000\", shardHost: \"10.10.21.163:27018\" }",   
  6.         "code" : 10276   
  7. }   
  8. > db.users.find()                                                                              
  9. error: { "$err" : "socket exception", "code" : 11002 }   

An error occurred!

Add the 164 server manually!

 
 
  1. > db.runCommand({addshard:"10.10.21.164:27017"});    
  2. {   
  3.         "ok" : 0,   
  4.         "errmsg" : "host is part of set: set163164 use replica set url format <setname>/<server1>,<server2>,...."   
  5. }   

An error occurred!

We can see that this configuration is incorrect!

The article is not complete. Continue to update!

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.