mongodb副本集和分片部署命令
2016-12-29 09:46
387 查看
在本文 mongos为 20000, config server 为 21000, shard1为 22001 , shard2为22002, shard3为22003.
mongod --configsvr --dbpath /ssd/mongodb/config/data --port 21000 --logpath /ssd/mongodb/config/log/config.log --fork
mongos --configdb 192.168.10.203:21000,192.168.10.204:21000,192.168.10.205:21000 --port 20000 --logpath /ssd/mongodb/mongos/log/mongos.log --fork
mongod --shardsvr --replSet shard1 --port 22001 --dbpath /ssd/mongodb/shard1/data --logpath /ssd/mongodb/shard1/log/shard1.log --fork --nojournal --oplogSize 10
mongod --shardsvr --replSet shard2 --port 22002 --dbpath /ssd/mongodb/shard2/data --logpath /ssd/mongodb/shard2/log/shard2.log --fork --nojournal --oplogSize 10
mongod --shardsvr --replSet shard3 --port 22003 --dbpath /ssd/mongodb/shard3/data --logpath /ssd/mongodb/shard3/log/shard3.log --fork --nojournal --oplogSize 10
任意一台机器:
mongo 127.0.0.1:22001
use admin
config = { _id:"shard1", members:[
{_id:0,host:"192.168.10.203:22001",priority:2},
{_id:1,host:"192.168.10.204:22001",priority:1},
{_id:2,host:"192.168.10.205:22001",arbiterOnly:true}
]
}
或
config = { _id:"shard1", members:[
{_id:0,host:"192.168.10.203:22001",priority:3},
{_id:1,host:"192.168.10.204:22001",priority:2},
{_id:2,host:"192.168.10.205:22001",priority:1}
]
}
rs.initiate(config);
mongo 127.0.0.1:22002
use admin
config = { _id:"shard2", members:[
{_id:0,host:"192.168.10.203:22002",priority:2},
{_id:1,host:"192.168.10.204:22002",priority:1},
{_id:2,host:"192.168.10.205:22002",arbiterOnly:true}
]
}
或
config = { _id:"shard2", members:[
{_id:0,host:"192.168.10.203:22002",priority:2},
{_id:1,host:"192.168.10.204:22002",priority:3},
{_id:2,host:"192.168.10.205:22002",priority:1}
]
}
rs.initiate(config);
mongo 127.0.0.1:22003
use admin
config = { _id:"shard3", members:[
{_id:0,host:"192.168.10.203:22003",priority:2},
{_id:1,host:"192.168.10.204:22003",priority:1},
{_id:2,host:"192.168.10.205:22003",arbiterOnly:true}
]
}
或
config = { _id:"shard3", members:[
{_id:0,host:"192.168.10.203:22003",priority:2},
{_id:1,host:"192.168.10.204:22003",priority:1},
{_id:2,host:"192.168.10.205:22003",priority:3}
]
}
rs.initiate(config);
mongo 127.0.0.1:20000
use admin
db.runCommand( { addshard : "shard1/192.168.10.203:22001,192.168.10.204:22001,192.168.10.205:22001"}
4000
);
db.runCommand( { addshard : "shard2/192.168.10.203:22002,192.168.10.204:22002,192.168.10.205:22002"});
db.runCommand( { addshard : "shard3/192.168.10.203:22003,192.168.10.204:22003,192.168.10.205:22003"});
db.runCommand( { listshards : 1 } );
移除分片
db.runCommand( { removeshard: "192.168.10.205:22005" } )
db.runCommand( { movePrimary: "database_name", to: "192.168.10.203:22004" })
db.runCommand( { removeshard: "192.168.10.205:22005" } )
使分片对于具体数据库和表生效
db.runCommand( { enablesharding :"testdb"});
db.tab4.ensureIndex({"username" : "hashed"}) //创建索引
db.runCommand( { shardcollection : "testdb.table1",key : {"username": "hashed"} } )
或 db.runCommand( { shardcollection : "testdb.table1",key : {_id: "hashed"} } )
mongo 127.0.0.1:20000
use testdb;
for (var i = 1; i <= 30000; i++){
db.table1.save({id:i,"test1":"testval1"});
}
db.table1.stats();
use config
db.shards.find()
db.databases.find()
db.chunks.find()
db.printShardingStatus()
mongod --configsvr --dbpath /ssd/mongodb/config/data --port 21000 --logpath /ssd/mongodb/config/log/config.log --fork
mongos --configdb 192.168.10.203:21000,192.168.10.204:21000,192.168.10.205:21000 --port 20000 --logpath /ssd/mongodb/mongos/log/mongos.log --fork
mongod --shardsvr --replSet shard1 --port 22001 --dbpath /ssd/mongodb/shard1/data --logpath /ssd/mongodb/shard1/log/shard1.log --fork --nojournal --oplogSize 10
mongod --shardsvr --replSet shard2 --port 22002 --dbpath /ssd/mongodb/shard2/data --logpath /ssd/mongodb/shard2/log/shard2.log --fork --nojournal --oplogSize 10
mongod --shardsvr --replSet shard3 --port 22003 --dbpath /ssd/mongodb/shard3/data --logpath /ssd/mongodb/shard3/log/shard3.log --fork --nojournal --oplogSize 10
任意一台机器:
mongo 127.0.0.1:22001
use admin
config = { _id:"shard1", members:[
{_id:0,host:"192.168.10.203:22001",priority:2},
{_id:1,host:"192.168.10.204:22001",priority:1},
{_id:2,host:"192.168.10.205:22001",arbiterOnly:true}
]
}
或
config = { _id:"shard1", members:[
{_id:0,host:"192.168.10.203:22001",priority:3},
{_id:1,host:"192.168.10.204:22001",priority:2},
{_id:2,host:"192.168.10.205:22001",priority:1}
]
}
rs.initiate(config);
mongo 127.0.0.1:22002
use admin
config = { _id:"shard2", members:[
{_id:0,host:"192.168.10.203:22002",priority:2},
{_id:1,host:"192.168.10.204:22002",priority:1},
{_id:2,host:"192.168.10.205:22002",arbiterOnly:true}
]
}
或
config = { _id:"shard2", members:[
{_id:0,host:"192.168.10.203:22002",priority:2},
{_id:1,host:"192.168.10.204:22002",priority:3},
{_id:2,host:"192.168.10.205:22002",priority:1}
]
}
rs.initiate(config);
mongo 127.0.0.1:22003
use admin
config = { _id:"shard3", members:[
{_id:0,host:"192.168.10.203:22003",priority:2},
{_id:1,host:"192.168.10.204:22003",priority:1},
{_id:2,host:"192.168.10.205:22003",arbiterOnly:true}
]
}
或
config = { _id:"shard3", members:[
{_id:0,host:"192.168.10.203:22003",priority:2},
{_id:1,host:"192.168.10.204:22003",priority:1},
{_id:2,host:"192.168.10.205:22003",priority:3}
]
}
rs.initiate(config);
mongo 127.0.0.1:20000
use admin
db.runCommand( { addshard : "shard1/192.168.10.203:22001,192.168.10.204:22001,192.168.10.205:22001"}
4000
);
db.runCommand( { addshard : "shard2/192.168.10.203:22002,192.168.10.204:22002,192.168.10.205:22002"});
db.runCommand( { addshard : "shard3/192.168.10.203:22003,192.168.10.204:22003,192.168.10.205:22003"});
db.runCommand( { listshards : 1 } );
移除分片
db.runCommand( { removeshard: "192.168.10.205:22005" } )
db.runCommand( { movePrimary: "database_name", to: "192.168.10.203:22004" })
db.runCommand( { removeshard: "192.168.10.205:22005" } )
使分片对于具体数据库和表生效
db.runCommand( { enablesharding :"testdb"});
db.tab4.ensureIndex({"username" : "hashed"}) //创建索引
db.runCommand( { shardcollection : "testdb.table1",key : {"username": "hashed"} } )
或 db.runCommand( { shardcollection : "testdb.table1",key : {_id: "hashed"} } )
mongo 127.0.0.1:20000
use testdb;
for (var i = 1; i <= 30000; i++){
db.table1.save({id:i,"test1":"testval1"});
}
db.table1.stats();
use config
db.shards.find()
db.databases.find()
db.chunks.find()
db.printShardingStatus()
相关文章推荐
- mongodb副本集和分片部署
- window下MongoDB副本集和分片高可靠性部署
- Linux下常用命令和应用部署
- ASP.NET应用程序的部署--兼谈aspnet_compiler.exe命令
- MOSS常用部署命令stsadm (转)
- ControlTier,基于命令的自动化部署工具
- 高性能Web服务器Nginx的配置与部署研究(4)Nginx常用命令
- MOSS常用部署命令stsadm
- 将module部署到was命令
- 从数据整理到telnet服务器再到was命令部署总结
- 在Tomcat中部署Java Web应用程序(jar命令打war包)
- tomcat5文档摘要:配置部署命令
- IP虚拟分片重组配置命令
- Maven使用deploy命令部署构建
- Windows部署——Dism命令工具(1)
- web部署时linux下的常用命令
- 部署DLL和安装windows服务的两个命令
- 基于Ping命令的IP分片数据分析 (IP4)
- bos简单打包部署批处理命令
- MOSS安装部署时常用到的命令