安装mongodb副本分片集群
2016-02-04 15:54
751 查看
一.mongodb安装配置
二.分别在master、slave1和slave2服务器上启动配置服务器
三.分别在master、slave1和slave2服务器上启动mongos服务器
四.分别在master、slave1和slave2服务器上配置分片副本集
五.设置副本集,必须使用admin数据库
2.设置第2个分片副本集
3.设置第3个分片副本集
六.串联路由服务器与分配副本集
七.分片测试
八.web监控页面
tar xzvf mongodb-linux-x86_64-rhel62-3.0.7.tgz mkdir -p /opt/hostkeeper/mongodb rm -rf /opt/hostkeeper/mongodb mv mongodb-linux-x86_64-rhel62-3.0.7 /opt/hostkeeper/mongodb mkdir -p /data/hostkeeper/mongodb/mongos/log mkdir -p /data/hostkeeper/mongodb/config/data mkdir -p /data/hostkeeper/mongodb/config/log mkdir -p /data/hostkeeper/mongodb/shard1/data mkdir -p /data/hostkeeper/mongodb/shard1/log mkdir -p /data/hostkeeper/mongodb/shard2/data mkdir -p /data/hostkeeper/mongodb/shard2/log mkdir -p /data/hostkeeper/mongodb/shard3/data mkdir -p /data/hostkeeper/mongodb/shard3/log chown hostkeeper:acfunadmin -R /opt/hostkeeper chown hostkeeper:acfunadmin -R /data/hostkeeper
二.分别在master、slave1和slave2服务器上启动配置服务器
numactl --interleave=all /opt/hostkeeper/mongodb/bin/mongod --configsvr --dbpath /data/hostkeeper/mongodb/config/data/ --httpinterface --rest --port 21000 --logpath /data/hostkeeper/mongodb/config/log/config.log --fork
三.分别在master、slave1和slave2服务器上启动mongos服务器
numactl --interleave=all /opt/hostkeeper/mongodb/bin/mongos --configdb 10.0.0.45:21000,10.0.0.57:21000,10.0.0.58:21000 --port 20000 --logpath /data/hostkeeper/mongodb/mongos/log/mongos.log --fork
四.分别在master、slave1和slave2服务器上配置分片副本集
numactl --interleave=all /opt/hostkeeper/mongodb/bin/mongod --shardsvr --replSet shard1 --port 22001 --dbpath /data/hostkeeper/mongodb/shard1/data --logpath /data/hostkeeper/mongodb/shard1/log/shard.log --fork --nojournal --oplogSize 10 numactl --interleave=all /opt/hostkeeper/mongodb/bin/mongod --shardsvr --replSet shard2 --port 22002 --dbpath /data/hostkeeper/mongodb/shard2/data --logpath /data/hostkeeper/mongodb/shard2/log/shard.log --fork --nojournal --oplogSize 10 numactl --interleave=all /opt/hostkeeper/mongodb/bin/mongod --shardsvr --replSet shard3 --port 22003 --dbpath /data/hostkeeper/mongodb/shard3/data --logpath /data/hostkeeper/mongodb/shard3/log/shard.log --fork --nojournal --oplogSize 10
五.设置副本集,必须使用admin数据库
1.设置第1个分片副本集 /opt/hostkeeper/mongodb/bin/mongo 10.0.0.45:22001/admin config = { _id:"shard1", members:[ {_id:0,host:"10.0.0.45:22001",priority:1}, {_id:1,host:"10.0.0.57:22001",priority:2}, {_id:2,host:"10.0.0.58:22001",arbiterOnly:true} ] }
rs.initiate(config); exit
2.设置第2个分片副本集
/opt/hostkeeper/mongodb/bin/mongo 10.0.0.57:22002/admin config = { _id:"shard2", members:[ {_id:0,host:"10.0.0.45:22002",arbiterOnly:true}, {_id:1,host:"10.0.0.57:22002",priority:1}, {_id:2,host:"10.0.0.58:22002",priority:2} ] }
rs.initiate(config); exit
3.设置第3个分片副本集
/opt/hostkeeper/mongodb/bin/mongo 10.0.0.58:22003/admin config = { _id:"shard3", members:[ {_id:0,host:"10.0.0.45:22003",priority:2}, {_id:1,host:"10.0.0.57:22003",arbiterOnly:true}, {_id:2,host:"10.0.0.58:22003",priority:1} ] }
rs.initiate(config); exit
六.串联路由服务器与分配副本集
/opt/hostkeeper/mongodb/bin/mongo 10.0.0.45:20000/admin #串联路由服务器与分配副本集1 db.runCommand( { addshard : "shard1/10.0.0.45:22001,10.0.0.57:22001,10.0.0.58:22001"}); #串联路由服务器与分配副本集2 db.runCommand( { addshard : "shard2/10.0.0.45:22002,10.0.0.57:22002,10.0.0.58:22002"}); #串联路由服务器与分配副本集3 db.runCommand( { addshard : "shard3/10.0.0.45:22003,10.0.0.57:22003,10.0.0.58:22003"});
七.分片测试
/opt/hostkeeper/mongodb/bin/mongo 10.0.0.45:20000/admin #指定testdb分片生效 db.runCommand( { enablesharding :"testdb"}); #指定数据库里需要分片的集合和片键 db.runCommand( { shardcollection : "testdb.table1",key : {id: 1} } ) #使用testdb use testdb; #插入测试数据 for (var i = 1; i <= 100000; i++) db.table1.save({id:i,"test1":"testval1"}); #查看分片情况如下 db.table1.stats();
八.web监控页面
http://10.0.0.45:22000[/code]
相关文章推荐
- mongodb与mysql相比的优缺点
- 【Tornado +Tenjin+MongoDB】- 初窥Tornado
- 二、MongoDB的高级查询(聚合、游标、管道、索引)
- mongoDB学习(三)--索引操作
- MongoDB学习笔记
- MongoDB运行状态、性能监控,分析
- MongoDB_索引
- 使用YCSB检测MongoDB
- 使用YCSB检测MongoDB
- MongoDB Kill Hang问题排查记录
- MongoDB Replication NetworkInterface
- MongoDB学习笔记
- Mongodb Wiredtiger存储引擎实现原理
- mongodb授权登录
- MongoDB使用教程系列文章--Driver原理(初始化)
- 一、Mongodb入门
- MongoDB的基本命令
- 准备阶段-mongodb数据库安装
- 无法打开MongoDB 28017监控页面
- php mongodb扩展安装