前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >基于副本集的分片高可用mongo集群安装 原

基于副本集的分片高可用mongo集群安装 原

作者头像
尚浩宇
发布2018-08-17 10:28:49
3690
发布2018-08-17 10:28:49
举报
文章被收录于专栏:杂烩

先上一张拓扑

所有mongo全部安装到本地(windows)

其中:

    分片端口27017

    副本1端口27018

    仲裁端口27019

    路由端口27020

    配置端口27021

在各mongo目录下的bin文件里创建配置文件

代码语言:javascript
复制
#shard.conf  
dbpath=D:\mongo\shard\mongodb-win32-x86_64-2.6.6\data  
logpath=D:\mongo\shard\mongodb-win32-x86_64-2.6.6\log\log.log  
pidfilepath=D:\mongo\shard\mongodb-win32-x86_64-2.6.6\pid\pid.pid  
directoryperdb=true  
logappend=true  
replSet=testrs  
bind_ip=127.0.0.1  
port=27017  
oplogSize=10000   
noprealloc=true
代码语言:javascript
复制
#slaver.conf  
dbpath=D:\mongo\shard\slaver\mongodb-win32-x86_64-2.6.6\data  
logpath=D:\mongo\shard\slaver\mongodb-win32-x86_64-2.6.6\log\log.log
pidfilepath=D:\mongo\shard\slaver\mongodb-win32-x86_64-2.6.6\pid\pid.pid 
directoryperdb=true  
logappend=true  
replSet=testrs  
bind_ip=127.0.0.1  
port=27018  
oplogSize=10000  
noprealloc=true
代码语言:javascript
复制
#arbiter.conf  
dbpath=D:\mongo\shard\arbiter\mongodb-win32-x86_64-2.6.6\data
logpath=D:\mongo\shard\arbiter\mongodb-win32-x86_64-2.6.6\log\log.log
pidfilepath=D:\mongo\shard\arbiter\mongodb-win32-x86_64-2.6.6\pid\pid.pid 
directoryperdb=true  
logappend=true  
replSet=testrs  
bind_ip=127.0.0.1 
port=27019
oplogSize=10000   
noprealloc=true
代码语言:javascript
复制
#mongos.conf  
logpath=D:\mongo\mongos\mongodb-win32-x86_64-2.6.6\log\log.log
pidfilepath=D:\mongo\mongos\mongodb-win32-x86_64-2.6.6\pid\pid.pid 
bind_ip=127.0.0.1 
port=27020
configdb=127.0.0.1:27021
代码语言:javascript
复制
#mongos.conf  
dbpath=D:\mongo\config\mongodb-win32-x86_64-2.6.6\data
logpath=D:\mongo\config\mongodb-win32-x86_64-2.6.6\log\log.log
pidfilepath=D:\mongo\config\mongodb-win32-x86_64-2.6.6\pid\pid.pid 
bind_ip=127.0.0.1 
port=27021

副本:

    启动分片、副本、仲裁

代码语言:javascript
复制
mongod -f 配置文件

连接到分片执行如下操作

代码语言:javascript
复制
use admin
cfg={_id:"testrs",members:[{_id:0,host:"127.0.0.1:27017",priority:2},{_id:1,host:"127.0.0.1:27018",priority:1},{_id:2,host:"127.0.0.1:27019",arbiterOnly:true}]};

分片:

    启动配置

代码语言:javascript
复制
mongod -f 配置文件

    启动路由

代码语言:javascript
复制
mongos -f 配置文件

    连接路由,使用admin添加分片

代码语言:javascript
复制
use admin
db.runCommand({"addShard":"testrs/127.0.0.1:27017"})

    开启分片及设置片键

代码语言:javascript
复制
db.runCommand({"enablesharding":"test"})
db.runCommand({"shardcollection":"test.person","key":{_id:'hashed'}})

    查看状态

代码语言:javascript
复制
printShardingStatus()
--- Sharding Status ---   sharding version: {    "_id" : 1,    "version" : 4,    "minCompatibleVersion" : 4,    "currentVersion" : 5,    "clusterId" : ObjectId("56a9e3c876c1778c5a28ae2b")}  shards:    {  "_id" : "testrs",  "host" : "testrs/127.0.0.1:27017,127.0.0.1:27018" }  databases:    {  "_id" : "admin",  "partitioned" : false,  "primary" : "config" }    {  "_id" : "test",  "partitioned" : true,  "primary" : "testrs" }        test.person            shard key: { "_id" : "hashed" }            chunks:                testrs  2            { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : testrs Timestamp(1, 1)             { "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : testrs Timestamp(1, 2)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016/01/28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档