window下Mongo分片部署安装


mongo下载地址:https://www.mongodb.org/dl/win32/x86_64-2008plus-ssl
我用的windows下版本:win32/mongodb-win32-x86_64-2008plus-ssl-3.4.14.zip

一.配置详情

分片1,port:1000;复制集,port 1001
分片2,port:2000;复制集,port 2001

配置服务,port:3000,复制集,port:3001,port:3002
路由服务,port:4000

二.将mongo服务放到d:/mongo目录下,并建立d:/mongoshare,其下建立文件夹route,log,config3000,config3001,config3002,s1000,s1001,s2000,s2001

三.安装

1.安装分片1
d:/mongo/bin/mongod.exe --shardsvr --replSet=copy1 --logpath "D:\mongoshare\log\s1000.log" --logappend --dbpath "D:\mongoshare\s1000" --port 1000 --serviceName "MongoDB_1000" --serviceDisplayName "MongoDB_1000" --install
2.安装复制集1
d:/mongo/bin/mongod.exe --shardsvr --replSet=copy1 --logpath "D:\mongoshare\log\s1001.log" --logappend --dbpath "D:\mongoshare\s1001" --port 1001 --serviceName "MongoDB_1001" --serviceDisplayName "MongoDB_1001" --install
3.安装分片2
d:/mongo/bin/mongod.exe --shardsvr --replSet=copy2 --logpath "D:\mongoshare\log\s2000.log" --logappend --dbpath "D:\mongoshare\s2000" --port 2000 --serviceName "MongoDB_2000" --serviceDisplayName "MongoDB_2000" --install
4.安装复制集2
d:/mongo/bin/mongod.exe --shardsvr --replSet=copy2 --logpath "D:\mongoshare\log\s2001.log" --logappend --dbpath "D:\mongoshare\s2001" --port 2001 --serviceName "MongoDB_2001" --serviceDisplayName "MongoDB_2001" --install
5.配置复制集1
d:/mongo/bin/mongo.exe localhost:1000 //连接
rs.initiate({_id: 'copy1', members: [{_id: 0, host: 'localhost:1000'}, {_id: 1, host: 'localhost:1001'}]})
rs.isMaster()//查看主节点
d:/mongo/bin/mongo.exe localhost:1001
rs.slaveOk()//设置主从复制
6.配置复制集2
d:/mongo/bin/mongo.exe localhost:2000
rs.initiate({_id: 'copy2', members: [{_id: 0, host: 'localhost:2000'}, {_id: 1, host: 'localhost:2001'}]})
rs.isMaster()//查看主节点 
d:/mongo/bin/mongo.exe localhost:2001
rs.slaveOk()//设置主从复制


7.安装配置服务

d:/mongo/bin/mongod.exe --logpath "D:\mongoshare\log\config3000.log" --dbpath "D:\mongoshare\config3000" --logappend --configsvr --replSet=configcopy --port 3000 --serviceName "MongoDB_3000" --serviceDisplayName "MongoDB_3000" --install

d:/mongo/bin/mongod.exe --replSet=configcopy --configsvr --logpath "D:\mongoshare\log\config3001.log" --logappend --dbpath "D:\mongoshare\config3001" --port 3001 --serviceName "MongoDB_3001" --serviceDisplayName "MongoDB_3001" --install

d:/mongo/bin/mongod.exe --replSet=configcopy --configsvr --logpath "D:\mongoshare\log\config3002.log" --logappend --dbpath "D:\mongoshare\config3002" --port 3002 --serviceName "MongoDB_3002" --serviceDisplayName "MongoDB_3002" --install
8.配置 配置服务
d:/mongo/bin/mongo.exe localhost:3000 //连接
rs.initiate({_id: 'configcopy', members: [{_id: 0, host: 'localhost:3000'}, {_id: 1, host: 'localhost:3001'}, {_id: 2, host: 'localhost:3002'}]})


9.安装路由服务
d:/mongo/bin/mongos.exe --port 4000 --configdb=configcopy/localhost:3000,localhost:3001,localhost:3002 --logpath=D:\mongoshare\log\route.log --serviceName "MongoDB_4000" --serviceDisplayName "MongoDB_4000" --install


10.添加分片设置
d:/mongo/bin/mongo.exe localhost:4000
use admin
db.runCommand({ addshard: 'copy1/localhost:1000,localhost:1001'})
db.runCommand({ addshard: 'copy2/localhost:2000,localhost:2001'}) //如果报错because a local database 'test' exists in another copy1,请删除各数据库的test集合
db.runCommand({ enablesharding: 'school'})
db.runCommand({ shardcollection: 'school.student', key: {_id: 1}})
11.查看分片信息
d:/mongo/bin/mongo.exe localhost:4000
db.printShardingStatus()
12.测试分片
d:/mongo/bin/mongo.exe localhost:4000
for(var i=0;i<500000;i++){
    db.student.insert({id:i,name:"小白"+i})
}


常用命令:
1.卸载
d:/mongo/bin/mongod.exe --remove --serviceName "MongoDB_4000"
2.查看复制集信息
rs.isMaster()
注意事项:
如果启动报错,请把相应data目录下的mongod.lock删除如果启动报错,请把相应data目录下的mongod.lock文件删除

mongoshare文件夹如下:

服务列表如下:


客户端连接如下:



发布了42 篇原创文章 · 获赞 25 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq812858143/article/details/79626088