mongodb高可用集群搭建

时间:2021-11-20 20:21:39

集群构架图如下:

mongodb高可用集群搭建

集群大致文件结构:(192.168.137.101节点)

mongodb高可用集群搭建

先搭建3个副本集

rs1/mongod.conf

mongodb高可用集群搭建

rs1/start.sh

mongodb高可用集群搭建

rs2/mongod.conf

mongodb高可用集群搭建

后面类似......

mongo 192.168.137.101:10001/admin

conf = {_id:"rs1",members:[{_id:0,host:"127.0.0.1:10001",priority:2},{_id:1,host:"127.0.0.1:20001",priority:1},{_id:2,host:"127.0.0.1:30001",arbiterOnly:true}]}

rs.initiate(conf)

rs.status()

开启配置节点

mongodb高可用集群搭建

mongodb高可用集群搭建

搭建路由节点

mongodb高可用集群搭建

mongodb高可用集群搭建

分片配置

conf = {addshard:"rs1/192.168.137.101:10001,192.168.137.102:10001,192.168.137.103:10001",name:"rs1"}

conf = {addshard:"rs2/192.168.137.101:20001,192.168.137.102:20001,192.168.137.103:20001",name:"rs2"}

conf = {addshard:"rs3/192.168.137.101:30001,192.168.137.103:30001,192.168.137.103:30001",name:"rs3"}

db.runCommand( { listshards : true } );

db.runCommand( { enablesharding :"testdb"}); db.runCommand( { shardcollection : "testdb.table1",key : {id: 1} } )

use  testdb; for (var i = 1; i <= 100000; i++) db.table1.save({id:i,"test1":"testval1"}); db.table1.stats();

附上配置:http://pan.baidu.com/s/14NGGQ