MongoDB分片群集的部署(用心描述,详细易懂)!!
概念:
MongoDB分片是使用多个服务器存储数据的方法,以支持巨大的数据存储和对数据进行存储
优势:
1、减少了每个分片需啊哟处理的请求数,群集可以提高自己的存储容量和吞吐量
2、减少了每个分片存储的数据
三个主要组件:
shard:分片服务器,用于存储实际的数据块,由多台服务器组成一个复制集承担,防止主机单点故障
config server:配置服务器,存储整个分片群集的配置信息,包括块信息
routers:前端路由,客户端由此进入,让整个群集看上去像单一数据库
如何部署MongoDB分片群集!!!
1、安装MongoDB3.2版本包和openssl-devel包
[root@localhost ~]# yum install openssl-devel -y
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mount.cifs //192.168.200.1/orc /abc
Password for root@//192.168.200.1/orc:
[root@localhost ~]# cd /abc
[root@localhost abc]# ls
mongodb-linux-x86_64-3.2.1.tgz //MongoDB 3.2版本
[root@localhost abc]# tar zxvf mongodb-linux-x86_64-3.2.1.tgz -C /opt
[root@localhost abc]# cd /opt
[root@localhost opt]# ls
mongodb-linux-x86_64-3.2.1 rh
[root@localhost opt]# mv mongodb-linux-x86_64-3.2.1/ /usr/local/mongodb
[root@localhost opt]# cd /usr/local/bin/
[root@localhost bin]# ln -s /usr/local/mongodb/bin/mongo /usr/bin/mongo //建立软连接
[root@localhost bin]# ln -s /usr/local/mongodb/bin/mongod /usr/bin/mongod
[root@localhost bin]# mkdir -p /data/mongodb/mongodb{1,2,3,4}
[root@localhost bin]# mkdir /data/mongodb/logs
[root@localhost bin]# touch /data/mongodb/logs/mongodb{1,2,3,4}.log
[root@localhost bin]# chmod -R 777 /data/mongodb/logs/*.log
[root@localhost bin]# ulimit -n 25000 //打开文件数量
[root@localhost bin]# ulimit -u 25000 //进程并发数
2、部署配置服务器
编辑mongodb1.conf配置文件,端口为37017,设置configsvr=true,启动配置服务器
[root@localhost bin]# vim mongodb1.con
port=37017
dbpath=/data/mongodb/mongodb1
logpath=/data/mongodb/logs/mongodb1.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
configsvr=true //开启配置服务器
3、某节点内存不足,从其它节点分配内存
[root@localhost bin]# sysctl -w vm.zone_reclaim_mode=0
vm.zone_reclaim_mode = 0
[root@localhost bin]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
[root@localhost bin]# echo never > /sys/kernel/mm/transparent_hugepage/defrag
[root@localhost bin]# mongod -f mongodb1.conf
about to fork child process, waiting until server is ready for connections.
forked process: 6895
child process started successfully, parent exiting
4、部署分片服务器
编辑mongodb2.conf配置文件,端口为47017,设置shardsvr=true;编辑mongodb3.conf配置文件,端口为47018,启动两个分片服务器
[root@localhost bin]# cp -p mongodb1.conf mongodb2.conf
[root@localhost bin]# vim mongodb2.conf
port=47017 //修改端口
dbpath=/data/mongodb/mongodb2
logpath=/data/mongodb/logs/mongodb2.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
shardsvr=true //开启分片服务器
[root@localhost bin]# cp -p mongodb2.conf mongodb3.conf
[root@localhost bin]# vim mongodb3.conf
port=47018
dbpath=/data/mongodb/mongodb3
logpath=/data/mongodb/logs/mongodb3.log
logappend=true
fork=true
maxConns=5000
storageEngine=mmapv1
shardsvr=true
[root@localhost bin]# mongod -f mongodb2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 7080
child process started successfully, parent exiting
[root@localhost bin]# mongod -f mongodb3.conf
about to fork child process, waiting until server is ready for connections.
forked process: 7107
child process started successfully, parent exiting
[root@localhost bin]# netstat -antp | grep mongod
tcp 0 0 0.0.0.0:37017 0.0.0.0:* LISTEN god
tcp 0 0 0.0.0.0:47017 0.0.0.0:* LISTEN god
tcp 0 0 0.0.0.0:47018 0.0.0.0:* LISTEN god
5、启动路由服务器
./mongos --help命令可以查看路由相关参数信息。chunkSize为数据块大小,默认为200M,这里将值设为1
[root@localhost bin]# ./mongos --port 27017 --fork --logpath=/usr/local/mongodb/bin/route.log --configdb 192.168.200.142:37017 --chunkSize 1
6、启用分片服务器
mongos> sh.addShard("192.168.200.142:47017")
{ "shardAdded" : "shard0000", "ok" : 1 }
mongos> sh.addShard("192.168.200.142:47018")
{ "shardAdded" : "shard0001", "ok" : 1 }
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5b4f68599dcf397cc4e7c598")
}
shards: //分片服务器开启
{ "_id" : "shard0000", "host" : "192.168.200.142:47017" }
{ "_id" : "shard0001", "host" : "192.168.200.142:47018" }
active mongoses:
"3.2.1" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migratio
7、分片功能
[root@localhost bin]# mongo
mongos> use school
switched to db school
mongos> for(var i=1;i<=10000;i++)db.users.insert({"id":i,"name":"jack"+i})
WriteResult({ "nInserted" : 1 })
mongos> show dbs
config 0.031GB
school 0.078GB
mongos> use school
switched to db school
mongos> show collections
system.indexes
users
mongos> db.users.find().limit(10) //查看头十行内容
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4ae"), "id" : 1, "name" : "jack1" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4af"), "id" : 2, "name" : "jack2" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b0"), "id" : 3, "name" : "jack3" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b1"), "id" : 4, "name" : "jack4" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b2"), "id" : 5, "name" : "jack5" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b3"), "id" : 6, "name" : "jack6" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b4"), "id" : 7, "name" : "jack7" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b5"), "id" : 8, "name" : "jack8" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b6"), "id" : 9, "name" : "jack9" }
{ "_id" : ObjectId("5b4f6a24ef33d588c0dbc4b7"), "id" : 10, "name" : "jack10" }
mongos> sh.status() //查看数据库分片信息
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5b4f68599dcf397cc4e7c598")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.200.142:47017" }
{ "_id" : "shard0001", "host" : "192.168.200.142:47018" }
active mongoses:
"3.2.1" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "school", "primary" : "shard0000", "partitioned" : false }
mongos> sh.enableSharding("school") //启用数据库分片
{ "ok" : 1 }
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5b4f68599dcf397cc4e7c598")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.200.142:47017" }
{ "_id" : "shard0001", "host" : "192.168.200.142:47018" }
active mongoses:
"3.2.1" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "school", "primary" : "shard0000", "partitioned" : true }
mongos> db.users.createIndex({"id":1}) //对users表创建索引
{
"raw" : {
"192.168.200.142:47017" : {
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
},
"ok" : 1
}
mongos> sh.shardCollection("school.users",{"id":1})//表分片
{ "collectionsharded" : "school.users", "ok" : 1 }
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"minCompatibleVersion" : 5,
"currentVersion" : 6,
"clusterId" : ObjectId("5b4f68599dcf397cc4e7c598")
}
shards:
{ "_id" : "shard0000", "host" : "192.168.200.142:47017" }
{ "_id" : "shard0001", "host" : "192.168.200.142:47018" }
active mongoses:
"3.2.1" : 1
balancer:
Currently enabled: yes
Currently running: no
Failed balancer rounds in last 5 attempts: 0
Migration Results for the last 24 hours:
No recent migrations
databases:
{ "_id" : "school", "primary" : "shard0000", "partitioned" : true }
school.users
shard key: { "id" : 1 }
unique: false
balancing: true
chunks:
shard0000 3
{ "id" : { "$minKey" : 1 } } -->> { "id" : 4682 } on : shard0000 Timestamp(1, 0)
{ "id" : 4682 } -->> { "id" : 9364 } on : shard0000 Timestamp(1, 1)
{ "id" : 9364 } -->> { "id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(1, 2) //分片成功
MongoDB分片群集的部署(用心描述,详细易懂)!!的更多相关文章
- 009.MongoDB分片群集部署
一 前期准备 1.1 组件说明 MongoDB分片群集包含以下组件: shard:每个分片是分片数据的子集.从MongoDB 3.6开始,必须将分片部署为副本集. mongos:mongos充当查询路 ...
- 【MangoDB分片】配置mongodb分片群集(sharding cluster)
配置mongodb分片群集(sharding cluster) Sharding cluster介绍 这是一种可以水平扩展的模式,在数据量很大时特给力,实际大规模应用一般会采用这种架构去构建monod ...
- 008.MongoDB分片群集概念及原理
一 MongoDB分片介绍 1.1 分片 Mongodb另一种集群,就是分片技术,可以满足MongoDB数据量大量增长的需求. 当MongoDB存储海量的数据时,一台机器可能不足以存储数据,也可能不足 ...
- mongodb 分片群集(sharding cluster)
实际环境架构 分别在3台机器运行一个mongod实例(称为mongod shard11,mongod shard12,mongod shard13)组织replica set1,作为cluster的s ...
- MongoDB DBA 实践8-----Linux系统Mongodb分片集群部署
在Linux系统中,主要是使用命令行进行mongodb的分片集群部署 一.先决条件 mongodb安装成功,明确路径, MongoDB的几个路径: /var/lib/mongodb /var/log/ ...
- MongoDB分片集群部署方案
前言 副本集部署是对数据的冗余和增加读请求的处理能力,却不能提高写请求的处理能力:关键问题是随着数据增加,单机硬件配置会成为性能的瓶颈.而分片集群可以很好的解决这一问题,通过水平扩展来提升性能.分片部 ...
- MongoDB分片集群-Sharded Cluster
分片概念 分片(sharding)是一种跨多台机器分布数据的方法, MongoDB使用分片来支持具有非常大的数据集和高吞吐量操作的部署. 换句话说:分片(sharding)是指将数据拆分,将其分散存在 ...
- Mongodb分片集群技术+用户验证
随着数据量持续增多,后续迟早会出现一台机器硬件瓶颈问题的.而mongodb主打的就是海量数据架构,“分片”就用这个来解决这个问题. 从图中可以看到有四个组件:mongos.config server. ...
- MongoDB 分片集群
每日一句 Medalist don't grow on trees, you have to nurture them with love, with hard work, with dedicati ...
随机推荐
- 洛谷 P1069 解题报告
P1069 细胞分裂 题目描述 \(Hanks\)博士是\(BT\) (\(Bio-Tech\),生物技术) 领域的知名专家.现在,他正在为一个细胞实验做准备工作:培养细胞样本. \(Hanks\) ...
- 1、原生javascript方法小汇
Js 对象 使用new 关键字来创建对象,举例如下, var a = new String();如构造函数无参数,则不必加括号, JS内部对象数组(Array)对象创建数组var myarray = ...
- 一文读懂 Spring Boot、微服务架构和大数据治理三者之间的故事
微服务架构 微服务的诞生并非偶然,它是在互联网高速发展,技术日新月异的变化以及传统架构无法适应快速变化等多重因素的推动下诞生的产物.互联网时代的产品通常有两类特点:需求变化快和用户群体庞大,在这种情况 ...
- Python_自定义有向图
directedGraph.py class DirectedGraph(object): def __init__(self,d): if isinstance(d,dict): self.__gr ...
- IT连创业系列:近期功能调整(小魔术功能从二级目录调整到一级栏目)
最近花了点时间,折腾了一下.NET Core,因此有几篇 Taurus.MVC + CYQ.Data 的文章出来. 这两天也顺带把 ASP.NET Aries 升级了一下功能, 也计划支持.NET C ...
- javascript中的隐式类型转化
javascript中的隐式类型转化 #隐式转换 ## "+" 字符串和数字 如果某个操作数是字符串或者能够通过以下步骤转换为字符串的话,+将进行拼接操作. 如果其中一个操作数是对 ...
- PAT1093: Count PAT's
1093. Count PAT's (25) 时间限制 120 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CAO, Peng The strin ...
- SSM-Spring-14:Spring中默认自动代理DefaultAdvisorAutoProxyCreator
------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 默认自动代理DefaultAdvisorAutoProxyCreator 本处没有什么要讲的,放原代码 ISo ...
- Spring MVC 的 Java Config ( 非 XML ) 配置方式
索引: 开源Spring解决方案--lm.solution 参看代码 GitHub: solution/pom.xml web/pom.xml web.xml WebInitializer.java ...
- 译MassTransit 生产消息
生产消息 应用程序或服务可以使用两种不同的方法生产消息.可以使用Sead发送消息,也可以使用Publish发布消息.每个方法的行为是非常不同的,但是通过查看每个特定方法所涉及的消息类型,可以很容易理解 ...