MongoDB 学习笔记之 分片和副本集混合运用
分片和副本集混合运用:
基本架构图:

搭建详细配置:
3个shard + 3个replicat set + 3个configserver + 3个Mongos
|
shardrsname |
Primary |
Secondary |
Secondary |
port |
|
bigdata-sh-a |
bigdata-sh-a1 |
bigdata-sh-a2 |
bigdata-sh-a3 |
28111 |
|
bigdata-sh-b |
bigdata-sh-b2 |
bigdata-sh-b1 |
bigdata-sh-b3 |
28112 |
|
bigdata-sh-c |
bigdata-sh-c3 |
bigdata-sh-c2 |
bigdata-sh-c1 |
28113 |
|
bigdata-cs |
configserver1 |
configserver2 |
configserver3 |
28200 |
在三台Linux机器的mongo根目录下建立如下文件夹:
Log:
/usr/local/mongodb/logs/a1
/usr/local/mongodb/logs/b1
/usr/local/mongodb/logs/c1
/usr/local/mongodb/logs/configserver1
DB:
/usr/local/mongodb/db/a1
/usr/local/mongodb/db/b1
/usr/local/mongodb/db/c1
/usr/local/mongodb/db/configserver1
bigdata-sh-a1.conf:
# mongod config systemLog:
destination: file
logAppend: true
path: /usr/local/mongodb/logs/a1/mongodb.log # Where and how to store data.
storage:
dbPath: /usr/local/mongodb/db/a1
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger: # how the process runs
# fork : fork and run in background
# pidFilePath:location of pidfile
processManagement:
fork: true
pidFilePath: /usr/local/mongodb/pidFile/mongod-a1.pid # network interfaces
# Listen to local interface only, comment to listen on all interfaces.
net:
port: 28111
bindIp: 0.0.0.0 #security: enabled disabled
#security:
# keyFile: /mongodb/keyfile
# clusterAuthMode: keyFile #operationProfiling:
operationProfiling:
slowOpThresholdMs: 1000
mode: slowOp #replication: replication:
replSetName: bigdata-sh-a #sharding: sharding:
clusterRole: shardsvr ## Enterprise-Only Options #auditLog: #snmp:
bigdata-sh-configserver1.conf:
# mongod config systemLog:
destination: file
logAppend: true
path: /usr/local/mongodb/logs/configserver1/mongodb.log # Where and how to store data.
storage:
dbPath: /usr/local/mongodb/db/configserver1
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger: # how the process runs
# fork : fork and run in background
# pidFilePath:location of pidfile
processManagement:
fork: true
pidFilePath: /usr/local/mongodb/pidFile/mongod-configserver1.pid # network interfaces
# Listen to local interface only, comment to listen on all interfaces.
net:
port: 28200
bindIp: 0.0.0.0 #security: enabled disabled
#security:
# keyFile: /mongodb/keyfile
# clusterAuthMode: keyFile #operationProfiling:
operationProfiling:
slowOpThresholdMs: 1000
mode: slowOp #replication: replication:
replSetName: bigdata-cs #sharding: sharding:
clusterRole: configsvr ## Enterprise-Only Options #auditLog: #snmp:
配置完成后,启动服务:
./mongod -f ../conf/bigdata-sh-a1.conf
./mongod -f ../conf/bigdata-sh-b1.conf
./mongod -f ../conf/bigdata-sh-c1.conf
./mongod -f ../conf/bigdata-sh-configserver1.conf
./mongod -f ../conf/bigdata-sh-a2.conf
./mongod -f ../conf/bigdata-sh-b2.conf
./mongod -f ../conf/bigdata-sh-c2.conf
./mongod -f ../conf/bigdata-sh-configserver2.conf
./mongod -f ../conf/bigdata-sh-a3.conf
./mongod -f ../conf/bigdata-sh-b3.conf
./mongod -f ../conf/bigdata-sh-c3.conf
./mongod -f ../conf/bigdata-sh-configserver3.conf
创建副本集:
./mongo hadoop1:28111/admin
use admin
rs.initiate()
rs.add("hadoop2:28111")
rs.add("hadoop3:28111")
./mongo hadoop2:28112/admin
rs.initiate()
rs.add("hadoop1:28112")
rs.add("hadoop3:28112")
./mongo hadoop3:28113/admin
rs.initiate()
rs.add("hadoop2:28113")
rs.add("hadoop1:28113")
./mongo hadoop1:28200/admin
rs.initiate()
rs.add("hadoop2:28200")
rs.add("hadoop3:28200")
在三台linux上启动Mongos:
./mongos --port 28300 --configdb bigdata-cs/hadoop1:28200,hadoop2:28200,hadoop3:28200 --fork --logpath /usr/local/mongodb/logs/mongos/mongos.log --bind_ip 0.0.0.0
连接其中一台Mongos,增加分片:
./mongo hadoop1:28300/admin
use admin
sh.addShard("bigdata-sh-a/hadoop1:28111,hadoop2:28111,hadoop3:28111")
sh.addShard("bigdata-sh-b/hadoop1:28112,hadoop2:28112,hadoop3:28112")
sh.addShard("bigdata-sh-c/hadoop1:28113,hadoop2:28113,hadoop3:28113")
sh.enableSharding("shop")
sh.shardCollection("shop.goods",{"goodid": 1});
插入大量数据进行验证:
for(var i=80002; i<=90001; i++){ db.goods.insert({goodid: i, name: "My first shard"}) }

大功告成!
MongoDB 学习笔记之 分片和副本集混合运用的更多相关文章
- MongoDB学习笔记(六)--复制集+sharding分片 && 总结
复制集+sharding分片 背景 主机 IP 服务及端口 Server A ...
- MongoDB学习笔记(五)--复制集 && sharding分片
主从复制 主从节点开启 主节 ...
- MongoDB学习笔记(四)--索引 && 性能优化
索引 基础索引 ...
- mongodb的分布式集群(4、分片和副本集的结合)
概述 前面3篇博客讲了mongodb的分布式和集群,当中第一种的主从复制我们差点儿不用,没有什么意义,剩下的两种,我们不论单独的使用哪一个.都会出现对应的问题.比較好的一种解决方式就是.分片和副本集的 ...
- MongoDB 3.4 分片 由副本集组成
要在真实环境中实现MongoDB分片至少需要四台服务器做分片集群服务器,其中包含两个Shard分片副本集(每个包含两个副本节点及一个仲裁节点).一个配置副本集(三个副本节点,配置不需要仲裁节点),其中 ...
- Mongodb 分片与副本集
测试搭建192.168.3.110mongos 30000,30001,30002config 40000,40001,40002shard1 50001,50002,50003shard2 5000 ...
- mongoDB 学习笔记纯干货(mongoose、增删改查、聚合、索引、连接、备份与恢复、监控等等)
最后更新时间:2017-07-13 11:10:49 原始文章链接:http://www.lovebxm.com/2017/07/13/mongodb_primer/ MongoDB - 简介 官网: ...
- MongoDB学习笔记:MongoDB 数据库的命名、设计规范
MongoDB学习笔记:MongoDB 数据库的命名.设计规范 第一部分,我们先说命名规范. 文档 设计约束 UTF-8 字符 不能包含 \0 字符(空字符),这个字符标识建的结尾 . 和 $ ...
- MongoDB学习笔记:快速入门
MongoDB学习笔记:快速入门 一.MongoDB 简介 MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统.在高负载的情况下,添加更多的节点,可以保证服务器性能.M ...
随机推荐
- poj 2828--Buy Tickets(线段树)
Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get ...
- Windows下升级Zabbix Agent
这段时间因工作上不太忙,就着手升级下zabbix,从3升级到最新版4.2,服务器端升级还挺快,就是客户端比较耗时了,往往就是看的越简单的东西越耗时间啊. Windows版本的zabbix agent下 ...
- 聊聊 Python 的单元测试框架(二):nose 和它的继任者 nose2
作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...
- HBase介绍、安装与应用案例
搭建环境 部署节点操作系统为CentOS,防火墙和SElinux禁用,创建了一个shiyanlou用户并在系统根目录下创建/app目录,用于存放 Hadoop等组件运行包.因为该目录用于安装hadoo ...
- Windows7关闭默认共享
注意:禁用默认共享会导致安装ORACLE时执行先决条件检测不通过,要想安装ORACLE得先打开共享. 1.win+r 运行里输入compmgmt.msc进入计算机管理,在共享文件夹里,去掉所有的盘共享 ...
- mybatis动态拼接条件的技巧 where 1=1 或者where标签
/** * 根据输入的学生信息进行条件检索 * 1. 当只输入用户名时, 使用用户名进行模糊检索: * 2. 当只输入邮箱时, 使用性别进行完全匹配 * 3. 当用户名 ...
- OPC—— KepServer.ServerState返回值为3和OPCConfig.exe配置文件的根目录
做开发没有对电脑的绝对管理员权限的问题,会出现很多意外,调试OPC是总是连接状态有时莫明返回3,提示 not configuration,问题在于: 没有以管理员权限运行OPCConfig.exe,导 ...
- Elastic Stack 笔记(三)Kibana5.6 安装
博客地址:http://www.moonxy.com 一.前言 Kibana 是 Elastic Stack 公司推出的一个针对 Elasticsearch 的开源分析及可视化平台,可以搜索.查看存放 ...
- (五)Linux内存管理zone_sizes_init
背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...
- Python语法基础之对象(字符串、列表、字典、元组)
转载自https://blog.csdn.net/lijinlon/article/details/81630154 字符串 String 定义:S = 'spam' 索引:S[0] = 's';S[ ...