MongoDB的sharding解决了海量存储和动态扩容的问题。但是遇到单点故障就显得无能为力了。MongoDB的副本集可以很好的解决单点故障的问题。所以就有了Sharding+Replica Sets的高可用架构了。

架构图如上所述

环境配置如下:

1:Shard服务器:使用Replica Sets确保每个数据节点的数据都有备份,自动容灾转移,自动恢复的能力。

2:Config服务器:使用3个配置服务器确保元数据完整性。

3:路由进程:使用3个路由进程实现平衡,提高客户端接入的性能。

4:6个分片进程:Shard A_1、Shard A_2、Shard A_3组成一个副本集Shard A。Shard B_1、Shard B_2

、Shard B_3组成另外一个副本集 Shard B。

Server IP 进程以及端口

Server A

192.168.91.128

Mongod Shard A_1:27017

Mongod Shard B_1:27018

Mongod config:30000

Mongos:40000

Server B

192.168.91.129

Mongod Shard A_2:27017

Mongod Shard B_2:27018

Mongod config:30000

Mongos:40000

Server C

192.168.91.130

Mongod Shard A_3:27017

Mongod Shard B_3:27018

Mongod config:30000

Mongos:40000

1:在Server A上启动mongod Shard A_1

[root@localhost mongodb]# ./bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath ./data/servera --logpath ./log/loga/sharda1 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 4838
child process started successfully, parent exiting

  

在Server B上启动mongod Shard A_2

[root@localhost mongodb]# ./bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath ./data/servera --logpath ./log/loga/shardb1 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 4540
child process started successfully, parent exiting

在Server C上启动mongod Shard A_3

[root@localhost mongodb]# ./bin/mongod --shardsvr --replSet shard1 --port 27017 --dbpath ./data/servera --logpath ./log/loga/shardc1 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 4505
child process started successfully, parent exiting

  

在3台服务器的任意一台上执行

[root@localhost mongodb]# ./bin/mongo
MongoDB shell version: 2.6.9
connecting to: test > config={_id:"shard1",members:[
... {_id:0,host:"192.168.91.128:27017"},
... {_id:1,host:"192.168.91.129:27017"},
... {_id:2,host:"192.168.91.130:27017"}
... ]}
{
"_id" : "shard1",
"members" : [
{
"_id" : 0,
"host" : "192.168.91.128:27017"
},
{
"_id" : 1,
"host" : "192.168.91.129:27017"
},
{
"_id" : 2,
"host" : "192.168.91.130:27017"
}
]
} > rs.initiate(config)
{
"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1
}

  

2:在Server A上启动mongod Shard B_1

[root@localhost mongodb]# ./bin/mongod --shardsvr --replSet shard2 --port 27018 --dbpath ./data/serverb --logpath ./log/logb/shardb1 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 5150
child process started successfully, parent exiting

在Server B上启动mongod Shard B_2

[root@localhost mongodb]# ./bin/mongod --shardsvr --replSet shard2 --port 27018 --dbpath ./data/serverb --logpath ./log/logb/shardb2 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 4861
child process started successfully, parent exiting

在Server C上启动mongod Shard B_3

[root@localhost mongodb]# ./bin/mongod --shardsvr --replSet shard2 --port 27018 --dbpath ./data/serverb --logpath ./log/logb/shardb3 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 4800
child process started successfully, parent exiting

  

[root@localhost mongodb]# ./bin/mongo --port 27018
MongoDB shell version: 2.6.9
connecting to: 127.0.0.1:27018/test
> config={_id:"shard2",members:[
... ... {_id:0,host:"192.168.91.128:27018"},
... ... {_id:1,host:"192.168.91.129:27018"},
... ... {_id:2,host:"192.168.91.130:27018"}
... ... ]}
{
"_id" : "shard2",
"members" : [
{
"_id" : 0,
"host" : "192.168.91.128:27018"
},
{
"_id" : 1,
"host" : "192.168.91.129:27018"
},
{
"_id" : 2,
"host" : "192.168.91.130:27018"
}
]
}
> rs.initiate(config)
{
"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1
}

注意:

到这里可以检查A、B、C上的相应的监听服务是否正常?

[root@localhost mongodb]# netstat -nat | grep 2701

  

副本集至此配置完毕。

3:分别在3台服务器上配置Config Server

在Server A上执行:

[root@localhost mongodb]# ./bin/mongod --port 30000 --dbpath ./data --logpath ./log/configlog --fork
about to fork child process, waiting until server is ready for connections.
forked process: 5430
child process started successfully, parent exiting

在Server B上执行:

[root@localhost mongodb]# ./bin/mongod --port 30000 --dbpath ./data --logpath ./log/configlog --fork
about to fork child process, waiting until server is ready for connections.
forked process: 5120
child process started successfully, parent exiting

在Server C上执行:

[root@localhost mongodb]# ./bin/mongod --port 30000 --dbpath ./data --logpath ./log/configlog --fork
about to fork child process, waiting until server is ready for connections.
forked process: 5056
child process started successfully, parent exiting

  

4:配置Route Process

在Server A上执行:

[root@localhost mongodb]# ./bin/mongos --configdb 192.168.91.128:30000,192.168.91.129:30000,192.168.91.130:30000 --port 40000 --logpath ./log/route.log --chunkSize 1 --fork
about to fork child process, waiting until server is ready for connections.
forked process: 5596
child process started successfully, parent exiting

chunkSize :指定chunk的大小,默认为200M。为了方便测试指定为1M。意思是当这个分片中插入的数据大于1M时候开始数据转移。

5:配置分片的表和片键

[root@localhost mongodb]# ./bin/mongo --port 40000
MongoDB shell version: 2.6.9
connecting to: 127.0.0.1:40000/test
mongos> use admin
switched to db admin
mongos> db.runCommand({addshard:"shard1/192.168.91.128:27017,192.168.91.129:27017,192.168.91.130:27017})
2015-05-06T00:38:37.360-0700 SyntaxError: Unexpected token ILLEGAL
mongos> db.runCommand({addshard:"shard1/192.168.91.128:27017,192.168.91.129:27017,192.168.91.130:27017"})
{ "shardAdded" : "shard1", "ok" : 1 }
mongos> db.runCommand({addshard:"shard2/192.168.91.128:27018,192.168.91.129:27018,192.168.91.130:27018"})
{ "shardAdded" : "shard2", "ok" : 1 }

  

mongos> db.person.insert({"uid":1,"uname":"gechong","tel":"158"})
WriteResult({ "nInserted" : 1 })
mongos> db.runCommand({enablesharding:"person"})
{ "ok" : 1 }
mongos> db.runCommand({shardcollection:"person.per",key:{_id:1}})
{ "collectionsharded" : "person.per", "ok" : 1 }

使用person库的per集合来做分片。片键是_id.

至此整个架构已经部署完毕。

MongoDB高可用架构:Replica Sets+Sharding的更多相关文章

  1. [MongoDB] 高可用架构方案

    一.缘由: 众所周知,Mongodb是在高速发展期,一些特性架构难免会发生变化.这里就总结下,我目前所知道的Mongodb 的高可用架构都有哪些.目前Mongodb版本3.2. 二.结构介绍: 1.R ...

  2. MongoDB高可用架构集群管理(一)

    MongoDB数据库核心的两个特点:第一个特点是副本集的自动切换,保证数据的高可靠.服务的高可用:第二个特点是自动分片.服务的横向扩展能力. (一)副本集架构 MongoDB的副本集是一组保持相同数据 ...

  3. 数据库高可用架构(MySQL、Oracle、MongoDB、Redis)

    一.MySQL MySQL小型高可用架构 方案:MySQL双主.主从 + Keepalived主从自动切换   服务器资源:两台PC Server 优点:架构简单,节省资源 缺点:无法线性扩展,主从失 ...

  4. [转]数据库高可用架构(MySQL、Oracle、MongoDB、Redis)

    一.MySQL   MySQL小型高可用架构 方案:MySQL双主.主从 + Keepalived主从自动切换 服务器资源:两台PC Server 优点:架构简单,节省资源 缺点:无法线性扩展,主从失 ...

  5. MongoDB整理笔记のReplica Sets + Sharding

    MongoDB Auto-Sharding 解决了海量存储和动态扩容的问题,但离实际生产环境所需的高可靠.高可用还有些距离,所以有了"Replica Sets + Sharding" ...

  6. MongoDB 高可用集群架构简介

    在大数据的时代,传统的关系型数据库要能更高的服务必须要解决高并发读写.海量数据高效存储.高可扩展性和高可用性这些难题.不过就是因为这些问题Nosql诞生了. 转载自严澜的博文——<如何搭建高效的 ...

  7. MongoDB高可用集群搭建(主从、分片、路由、安全验证)

    目录 一.环境准备 1.部署图 2.模块介绍 3.服务器准备 二.环境变量 1.准备三台集群 2.安装解压 3.配置环境变量 三.集群搭建 1.新建配置目录 2.修改配置文件 3.分发其他节点 4.批 ...

  8. MongoDB 高可用集群副本集+分片搭建

    MongoDB 高可用集群搭建 一.架构概况 192.168.150.129192.168.150.130192.168.150.131 参考文档:https://www.cnblogs.com/va ...

  9. MogoDB(6)--mongoDB高可用和4.0特性

    5.1.MongoDB 用户管理 1.用户管理1.1.添加用户为 testdb 添加 tom 用户 use testdb db.createUser({user:"tom",pwd ...

随机推荐

  1. 开源项目MultiChoiceAdapter详解(五)——可扩展的MultiChoiceBaseAdapter

    上次写到了开源项目MultiChoiceAdapter详解(四)——MultiChoiceBaseAdapter的使用,其实我们仍旧可以不使用ActionMode的,所以这里就写一个自己扩展的方法. ...

  2. caffe 生成检测框并绘图

    Step 1 使用训练好的模型检测图片: build/examples/ssd/ssd_detect.bin models/VGGNet/VOC0712/SSD_300x300/deploy.prot ...

  3. SpringBoot yml 配置 多配置文件,开发环境,生产环境配置文件分开

    原文地址:https://www.cnblogs.com/baoyi/p/SpringBoot_YML.html 1. 在 spring boot 中,有两种配置文件,一种是application.p ...

  4. usaco 洛谷 P2694 接金币 题解

    题目描述 在二维坐标系里,有N个金币,编号0至N-1.初始时,第i个金币的坐标是(Xi,Yi).所有的金币每秒向下垂直下降一个单位高度,例如有个金币当前坐标是(xf, yf),那么t秒后金币所在的位置 ...

  5. maven与jdk版本不一致报:Unsupported major.minor version 51.0

    I recently uninstalled Java 8, to use Java 6 as I want my code/creations to be usable by more people ...

  6. postgresql共享内存的三个结构体

    本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/16105797 postgresql的共享内存维护主要 ...

  7. [算法导论]quicksort algorithm @ Python

    算法导论上面快速排序的实现. 代码: def partition(array, left, right): i = left-1 for j in range(left, right): if arr ...

  8. iOS开发-类簇(Class Cluster)

    类簇(Class  Cluster)是定义相同的接口并提供相同功能的一组类的集合,仅公开接口的抽象类也可以称之为类簇的公共类,每个具体类的接口有公共类的接口抽象化,并隐藏在簇的内部.这些类一般不能够直 ...

  9. Generate Parentheses leetcode java

    题目: Given n pairs of parentheses, write a function to generate all combinations of well-formed paren ...

  10. 如何去除图片上的文字(PS使用教程)

    很多时候由于工作的需要,需要对我们的图片进行修改,修改的同时还想要保存我们的图片背景,所以很多人就不知道怎么弄了,小编跟大家分享一下使用PS如何简单的去掉图片上的文字,希望对大家有所帮助! 方法/步骤 ...