---
title: "搭建Mongodb集群：分片Sharding+副本集Replica Set"
author: "sblig"
date: "2014-05-26T15:00:46Z"
tags: []
categories: ["编程语言"]
slug: "mongodb-sharding-replica-set"
draft: false
lastmod: "2014-05-26T15:00:46Z"
id: 2071376
url: "https://sblig.iteye.com/blog/2071376"
---

架构图如下：
 客户请求： client
   路由：Mongs1 Mongs2 Mongs3
        40000  40100  402000
   配置：        config1     config2   config3
        config:30000	30100	30200
   副本集：
        rs1:  27017 27117 27217
        rs2:  27018 27118 27218
        rs3:  27019 27119 27219

添加windows服务形式启动：
rs1:
sc.exe create MongoDB0 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb0.cfg\"" DisplayName= "MongoDB0" start= "auto"
sc.exe create MongoDB1 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb1.cfg\"" DisplayName= "MongoDB1" start= "auto"
sc.exe create MongoDB2 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb2.cfg\"" DisplayName= "MongoDB2" start= "auto"
sc.exe create config1 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\config1.cfg\"" DisplayName= "config1" start= "auto"


rs2:
sc.exe create MongoDB3 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb3.cfg\"" DisplayName= "MongoDB3" start= "auto"
sc.exe create MongoDB4 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb4.cfg\"" DisplayName= "MongoDB4" start= "auto"
sc.exe create MongoDB5 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb5.cfg\"" DisplayName= "MongoDB5" start= "auto"
sc.exe create config2 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\config2.cfg\"" DisplayName= "config2" start= "auto"


rs3:
sc.exe create MongoDB6 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb6.cfg\"" DisplayName= "MongoDB6" start= "auto"
sc.exe create MongoDB7 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb7.cfg\"" DisplayName= "MongoDB7" start= "auto"
sc.exe create MongoDB8 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\mongodb8.cfg\"" DisplayName= "MongoDB8" start= "auto"
sc.exe create config3 binPath= "\"D:\mongodb\bin\mongod.exe\" --service --config=\"D:\mongodb\db\config3.cfg\"" DisplayName= "config3" start= "auto"


net start MongoDB0
net start MongoDB1
net start MongoDB2
net start MongoDB3
net start MongoDB4
net start MongoDB5
net start MongoDB6
net start MongoDB7
net start MongoDB8
net start config1
net start config2
net start config3