MongoDB AutoSharding+Replication sets稳定性测试

数据库 其他数据库 数据库运维 MongoDB
如果插入2000W条数据,163和164相同大小,165属于分片数据。如何进行稳定性测试,会如何呢?

单Replication sets设计:

如图所示,10.9.3.228只启动Mongos和config两个服务

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

注意:Mongos里面的ip和端口是config服务的ip和端口

先进性配置AutoSharding

163的shardv已经启动了,只要启动下165服务器的autoSharding服务

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

再在228服务器上进行相应Sharding配置

use admin

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

然后分别在163和164服务器上启动rep服务,163要单独启动shard服务

163:

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

164:

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

继续配置163和164的Replication

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

至此Replication sets配置成功!

至此AutoSharding+Rep配置成功。然后进行测试稳定性阶段。(刚才注意 应该先配sharding再配Replication)

先看下结果:

可以看到,总共插入2000W条数据,163和164相同大小 165属于分片 数据。

我现在进行稳定性测试:

断掉163服务器。

Mongos那再相应进行查询:

> db.users.find()   
error: { "$err" : "error querying server: 10.10.21.163:27018""code" : 13633 }   
> db.users.find()   
error: {   
        "$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\" }",   
        "code" : 10276   
}   
> db.users.find()                                                                              
error: { "$err" : "socket exception""code" : 11002 }   
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

直接出现错误!

再进行手动添加164服务器!

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

还是出错!

可见这样配置是有问题的!

文章未完,继续更新中!

原文链接:http://blog.csdn.net/crazyjixiang/article/details/6636671

【编辑推荐】

  1. 教你如何利用MySQL学习MongoDB
  2. 说说MongoDB的基础
  3. 如何用Java操作MongoDB
  4. MongoDB分布式自动分片(Auto-sharding)研究
  5. MongoDB 1000W级数据Insert和Query性能测试
责任编辑:艾婧 来源: Crazybaby's blog
相关推荐

2023-04-26 18:36:13

2009-02-04 09:22:40

稳定性服务器测试

2019-06-17 15:48:51

服务器测试方法软件

2022-09-15 08:33:27

安全生产系统Review

2023-06-30 08:43:36

2023-09-07 15:16:06

软件开发测试

2010-08-14 09:46:05

2011-12-21 09:46:46

程序员

2009-07-27 10:08:14

2011-04-27 21:54:45

2011-08-01 11:03:15

2020-07-13 08:10:13

软件设计系统

2020-07-28 08:07:14

ElasticSear

2009-10-30 18:10:05

2013-11-01 11:16:16

苹果OS XOS X Maveri

2024-12-12 09:18:21

2013-05-23 16:00:20

负载均衡网络优化网络升级

2022-05-05 19:20:24

数据系统稳定性峰会数据系统

2009-12-23 18:18:04

2023-10-09 07:24:58

数据稳定性治理数据处理
点赞
收藏

51CTO技术栈公众号