版权声明:技术成长的艰难岁月,沧桑的是容颜,不变的是真心,虽然我不是特别喜欢Code ! https://blog.csdn.net/qq_25037705/article/details/79179797
1、windows服务安装
安装windows服务不分先后顺序,配置服务和路由服务启动的时候,必须先启动配置
//分片1(副本集)
D:\mongo\bin\mongod --config D:\mongo\shard11\shard11.conf --serviceName "shard11" --serviceDisplayName "shard11" --install
D:\mongo\bin\mongod --config D:\mongo\shard12\shard12.conf --serviceName "shard12" --serviceDisplayName "shard12" --install
D:\mongo\bin\mongod --config D:\mongo\shard13\shard13.conf --serviceName "shard13" --serviceDisplayName "shard13" --install
//分片2(副本集)
D:\mongo\bin\mongod --config D:\mongo\shard21\shard21.conf --serviceName "shard21" --serviceDisplayName "shard21" --install
D:\mongo\bin\mongod --config D:\mongo\shard22\shard22.conf --serviceName "shard22" --serviceDisplayName "shard22" --install
D:\mongo\bin\mongod --config D:\mongo\shard23\shard23.conf --serviceName "shard23" --serviceDisplayName "shard23" --install
//配置服务器
D:\mongo\bin\mongod --config D:\mongo\config\config.conf --serviceName "config" --serviceDisplayName "servesconfig" --install
//路由服务器
D:\mongo\bin\mongos --config D:\mongo\route\route.conf --serviceName "route" --serviceDisplayName "serveroute" --install
2、配置环境变量
3、启动服务
管理员启动cmd
3.1、启动分片服务
net start shard11
net start shard12
net start shard13
net start shard21
net start shard22
net start shard23
3.2、初始化副本集
副本集1
进入10011
mongo --port 10001
设置配置变量
config={_id:'rs1',members:[{_id:0,host:'127.0.0.1:10001'},{_id:1,host:'127.0.0.1:10002'},{_id:2,host:'127.0.0.1:10003',arbiterOnly:true}]}
初始化配置
rs.initiate(config)
查询配置状态
rs.status()
副本集2
进入20011
mongo --port 20001
config={_id:'rs2',members:[{_id:0,host:'127.0.0.1:20001'},{_id:1,host:'127.0.0.1:20002'},{_id:2,host:'127.0.0.1:20003',arbiterOnly:true}]}
rs.initiate(config)
rs.status()
配置服务器副本集
mongo --port 30000
config={_id:'conf',members:[{_id:0,host:'127.0.0.1:30000'}]}
rs.initiate(config)
注意:其中10003、20003地址后面的arbiterOnly:true 表明这是仲裁服务器的意思
3.3、启动配置服务
net start config
net start route