一键部署MongoDB集群Windows版

因为周末在家手头没有虚拟机,所以在windows下单机完成部署要求,并编写bat运行脚本。
1、创建配置文件及相关目录
总的启动脚本如下(startmc.bat):
rem m1
start mongod.exe --config=../config/m1/s1_1
start mongod.exe --config=../config/m1/s1_2
start mongod.exe --config=../config/m1/c1_1
start mongod.exe --config=../config/m1/a1_1
start mongod.exe --config=../config/m1/a1_2

rem m2
start mongod.exe --config=../config/m2/s2_1
start mongod.exe --config=../config/m2/s2_2
start mongod.exe --config=../config/m2/c2_1
start mongod.exe --config=../config/m2/a2_1
start mongod.exe --config=../config/m2/a2_2

rem m3
start mongod.exe --config=../config/m3/s3_1
start mongod.exe --config=../config/m3/s3_2
start mongod.exe --config=../config/m3/c3_1
start mongod.exe --config=../config/m3/a3_1
start mongod.exe --config=../config/m3/a3_2


start mongos.exe --config=../config/m1/s1
start mongos.exe --config=../config/m2/s2
start mongos.exe --config=../config/m3/s3
2、配置文件
配置文件分别分为几个集群文件夹,分别为m1、m2、m3
每个文件夹下分别包含了两个分片(s*_1,s*_2)、一个config(c*_1)、一个mongos(s*)、两个仲裁节点(a*_1,a*_2)(以m1为例,其他两个文件夹对应log及db文件不一样,端口号分别加1000):
a1_1(注意Windows下没有fork,所以在bat中使用start建立不同进程):
dbpath=../data/db/a1_1
logpath=../data/a1_1.log
port=8451
shardsvr=true
replSet=shard1
logappend=true
oplogSize=2048
storageEngine=wiredTiger
nojournal=true
a1_2:
dbpath=../data/db/a1_2
logpath=../data/a1_2.log
port=8452
shardsvr=true
replSet=shard2
logappend=true
oplogSize=2048
storageEngine=wiredTiger
nojournal=true
c1_1:
dbpath=../data/db/c1_1
logpath=../data/c1_1.log
port=8441
configsvr=true
logappend=true
oplogSize=2048
storageEngine=wiredTiger
nojournal=true
s1:
logpath=../data/s1.log
port=8440
chunkSize=100
logappend=true
configdb=localhost:8441,localhost:8541,localhost:8641
s1_1:
dbpath=../data/db/s1_1
logpath=../data/s1_1.log
port=8442
shardsvr=true
replSet=shard1
logappend=true
oplogSize=2048
storageEngine=wiredTiger
nojournal=true
s1_2:
dbpath=../data/db/s1_2
logpath=../data/s1_2.log
port=8443
shardsvr=true
replSet=shard2
logappend=true
oplogSize=2048
storageEngine=wiredTiger
nojournal=true


3、进行分片相应设置
use admin
config = {_id: 'shard1', members:[ {_id:0, host: 'localhost:8442'}, {_id:1, host:'localhost :8542 '}, {_id:2, host:'localhost :8642 ',slaveDelay:7200,priority:0} , {_id:3, host:'localhost :8451 ',arbiterOnly:true} , {_id:4, host:'localhost :8551 ',arbiterOnly:true} , {_id:5, host:'localhost :8651 ',arbiterOnly:true} ] };
rs.initiate(config);
config = {_id: 'shard2', members:[ {_id:0, host: 'localhost:8443'}, {_id:1, host:'localhost :8543 '}, {_id:2, host:'localhost :8643 ',slaveDelay:7200,priority:0} , {_id:3, host:'localhost :8452 ',arbiterOnly:true} , {_id:4, host:'localhost :8552 ',arbiterOnly:true} , {_id:5, host:'localhost :8652 ',arbiterOnly:true} ] };
rs.initiate(config);

use admin
db.runCommand( { addshard:"shard1/ localhost:8442 , localhost :8542 " ,name:"s1"} );
db.runCommand( { addshard:"shard2/ localhost:8443 , localhost :8543 " ,name:"s2"} );
db.runCommand( { listshards : 1 } )
3、目录结构及运行情况
配置文件目录(m1为例):
一键部署MongoDB集群Windows版_第1张图片
文件记录log
一键部署MongoDB集群Windows版_第2张图片
db文件夹
一键部署MongoDB集群Windows版_第3张图片
运行程序(15+3个进程)
一键部署MongoDB集群Windows版_第4张图片 一键部署MongoDB集群Windows版_第5张图片
分片情况:
一键部署MongoDB集群Windows版_第6张图片

你可能感兴趣的:(技术淘金)