读书人

MongoDB cluster 筹建

发布时间: 2012-07-16 15:45:00 作者: rapoo

MongoDB cluster 搭建

1.配置两个shard

?

mongod.exe --shardsvr --dbpath D:\temp\cluster\shard11 --replSet shard1 --port 27017 --oplogSize 100 --logpath D:\temp\cluster\shard11\shard11.log --logappendmongod.exe --shardsvr --dbpath D:\temp\cluster\shard12 --replSet shard1 --port 27017 --oplogSize 100 --logpath D:\temp\cluster\shard12\shard12.log --logappendmongod.exe --shardsvr --dbpath D:\temp\cluster\shard13 --replSet shard1 --port 27017 --oplogSize 100 --logpath D:\temp\cluster\shard13\shard13.log --logappendmongo.exe localhost:27017config = {_id: 'shard1', members: [                          {_id: 0, host: 'hostname1:27017'},                          {_id: 1, host: 'hostname2:27017'},                          {_id: 2, host: 'hostname3:27017'}]           }           rs.initiate(config);mongod.exe --shardsvr --dbpath D:\temp\cluster\shard21 --replSet shard2 --port 27018 --oplogSize 100 --logpath D:\temp\cluster\shard21\shard21.log --logappendmongod.exe --shardsvr --dbpath D:\temp\cluster\shard22 --replSet shard2 --port 27018 --oplogSize 100 --logpath D:\temp\cluster\shard22\shard22.log --logappendmongod.exe --shardsvr --dbpath D:\temp\cluster\shard23 --replSet shard2 --port 27018 --oplogSize 100 --logpath D:\temp\cluster\shard23\shard23.log --logappendmongo.exe localhost:27018config = {_id: 'shard2', members: [                          {_id: 0, host: 'hostname1:27018'},                          {_id: 1, host: 'hostname2:27018'},                          {_id: 2, host: 'hostname3:27018'}]           }           rs.initiate(config);

?

2 配置config server

?

mongod.exe --configsvr --dbpath D:\temp\cluster\config --port 20000 --oplogSize 100 --logpath D:\temp\cluster\config\config.log --logappendmongod.exe --configsvr --dbpath D:\temp\cluster\config --port 20000 --oplogSize 100 --logpath D:\temp\cluster\config\config.log --logappendmongod.exe --configsvr --dbpath D:\temp\cluster\config --port 20000 --oplogSize 100 --logpath D:\temp\cluster\config\config.log --logappend

?

3 配置路由节点

?

mongos.exe --configdb hostname1:20000,hostname2:20000,hostname3:20000 --port 30000 --chunkSize 5 --logpath D:\temp\cluster\mongos.log --logappendmongos.exe --configdb hostname1:20000,hostname2:20000,hostname3:20000 --port 30000 --chunkSize 5 --logpath D:\temp\cluster\mongos.log --logappendmongos.exe --configdb hostname1:20000,hostname2:20000,hostname3:20000 --port 30000 --chunkSize 5 --logpath D:\temp\cluster\mongos.log --logappend

?

4. 添加shard

?

mongo.exe hostname1:30000/admindb.runCommand( { addshard : "shard1/hostname1:27017,hostname2:27017,hostname3:27017",name:"s1",maxsize:20480} );db.runCommand( { addshard : "shard2/hostname1:27018,hostname2:27018,hostname3:27018",name:"s2",maxsize:20480} );

?

?5 设置数据库分片和集合分片

?

use admindb.runCommand( { enablesharding : "test"} );db.runCommand({shardcollection:'test.hello',key:{id1:1,id2:1}})

?

读书人网 >其他数据库

热点推荐