单Replication sets设计:
创新互联建站长期为近千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为黄浦企业提供专业的成都网站设计、成都网站建设,黄浦网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。
如图所示,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
注意: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
再在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 }
- > db.runCommand({shardcollection:"test.users",key:{_id:1}})
- { "collectionsharded" : "test.users", "ok" : 1 }
然后分别在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
164:
- [root@localhost bin]# cat runServerShard.sh
- ./mongod --dbpath=../data --logpath=../data/shardsvr_logs.txt --fork --replSet set163164
继续配置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
- }
至此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 }
直接出现错误!
再进行手动添加164服务器!
- > db.runCommand({addshard:"10.10.21.164:27017"});
- {
- "ok" : 0,
- "errmsg" : "host is part of set: set163164 use replica set url format
/ , ,...." - }
还是出错!
可见这样配置是有问题的!
文章未完,继续更新中!
当前标题:MongoDBAutoSharding+Replicationsets稳定性测试
地址分享:http://www.mswzjz.cn/qtweb/news39/130039.html
攀枝花网站建设、攀枝花网站运维推广公司-贝锐智能,是专注品牌与效果的网络营销公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 贝锐智能