设为首页 加入收藏

TOP

MongoDB搭建cluster
2014-11-24 07:25:20 来源: 作者: 【 】 浏览:0
Tags:MongoDB 搭建 cluster

配置两个shard
Java代码
mongod.exe --shardsvr --dbpath D:\temp\cluster\shard11 --replSet shard1 --port 27017 --oplogSize 100 --logpath D:\temp\cluster\shard11\shard11.log --logappend
mongod.exe --shardsvr --dbpath D:\temp\cluster\shard12 --replSet shard1 --port 27017 --oplogSize 100 --logpath D:\temp\cluster\shard12\shard12.log --logappend
mongod.exe --shardsvr --dbpath D:\temp\cluster\shard13 --replSet shard1 --port 27017 --oplogSize 100 --logpath D:\temp\cluster\shard13\shard13.log --logappend
mongo.exe localhost:27017 www.2cto.com
config = {_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 --logappend
mongod.exe --shardsvr --dbpath D:\temp\cluster\shard22 --replSet shard2 --port 27018 --oplogSize 100 --logpath D:\temp\cluster\shard22\shard22.log --logappend
mongod.exe --shardsvr --dbpath D:\temp\cluster\shard23 --replSet shard2 --port 27018 --oplogSize 100 --logpath D:\temp\cluster\shard23\shard23.log --logappend
mongo.exe localhost:27018 www.2cto.com
config = {_id: 'shard2', members: [
{_id: 0, host: 'hostname1:27018'},
{_id: 1, host: 'hostname2:27018'},
{_id: 2, host: 'hostname3:27018'}]
}
rs.initiate(config);
2 配置config server
Java代码
mongod.exe --configsvr --dbpath D:\temp\cluster\config --port 20000 --oplogSize 100 --logpath D:\temp\cluster\config\config.log --logappend
mongod.exe --configsvr --dbpath D:\temp\cluster\config --port 20000 --oplogSize 100 --logpath D:\temp\cluster\config\config.log --logappend
mongod.exe --configsvr --dbpath D:\temp\cluster\config --port 20000 --oplogSize 100 --logpath D:\temp\cluster\config\config.log --logappend
3 配置路由节点
Java代码
mongos.exe --configdb hostname1:20000,hostname2:20000,hostname3:20000 --port 30000 --chunkSize 5 --logpath D:\temp\cluster\mongos.log --logappend
mongos.exe --configdb hostname1:20000,hostname2:20000,hostname3:20000 --port 30000 --chunkSize 5 --logpath D:\temp\cluster\mongos.log --logappend
mongos.exe --configdb hostname1:20000,hostname2:20000,hostname3:20000 --port 30000 --chunkSize 5 --logpath D:\temp\cluster\mongos.log --logappend www.2cto.com
4. 添加shard
Java代码
mongo.exe hostname1:30000/admin
db.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 设置 数据库分片和集合分片
Java代码
use admin
db.runCommand( { enablesharding : "test"} );
db.runCommand({shardcollection:'test.hello',key:{id1:1,id2:1}})
作者 aryanwang
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇批量分配空表空间 下一篇redis批量删除key,与出现的问题..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·PostgreSQL 索引 - (2025-12-25 22:20:43)
·MySQL Node.js 连接 (2025-12-25 22:20:41)
·SQL 撤销索引、表以 (2025-12-25 22:20:38)
·Linux系统简介 (2025-12-25 21:55:25)
·Linux安装MySQL过程 (2025-12-25 21:55:22)