本文主要介绍mongo副本集构造(mongodb副本集和分片哪个好),下面一起看看mongo副本集构造(mongodb副本集和分片哪个好)相关资讯。
前言最近因为工作原因,学会了使用mondb数据库,这是最常用的nodql数据库,有些数据库的排名已经上升到了前六。本文介绍如何搭建一个高可用的mondb集群,分享给大家参考。在构建集群之前,我们需要了解几个概念:路由、碎片、副本集、配置服务器等等。相关概念先看一张图:从图中可以看到四个组件:mons、配置服务器、碎片和副本集。mons,门户数据库集群的请求,所有请求都通过mons协调,不需要在应用中添加路径选择。mons本身就是一个请求分发中心,负责将相应的数据请求转发给相应的共享服务器。在生产环境中,通常会有比mons更多的请求,这就不可避免地会出现mondb请求挂起的情况。配置服务器,顾名思义,是存储所有数据库的元信息(路由、连接器)配置的配置服务器。mons本身并不实际存储分区服务器的路由信息和数据,只是在内存中缓存,并配置存储在服务器上的数据。在第一个月启动或关闭它,以便从配置服务器加载配置信息。以后如果服务器配置信息发生变化,就会更新mons来更新其状态,这样mons就可以继续准确路由。通常有多个配置服务器。配置服务器位于生产环境中,因为它存储元数据分段路由并防止数据丢失!shard,碎片化是数据库分割分散在不同机器上的过程。将数据分散到不同的机器上,没有强大的服务器,可以存储更多的数据,处理更多的负载。基本思想是将收集到的块分成几块。每个部分只负责总数据的一部分。最后,使用均衡器来平衡每个数据段(数据迁移)。副本集,中文翻译副本集,其实就是一个备份碎片,防止碎片挂起后数据丢失。复制提供了数据的冗余备份,并将数据副本存储在多个服务器中,提高了数据可用性,确保了数据安全性。仲裁(arbitration)是mondb-replica set的一个实例,它不保存数据。仲裁节点使用的资源最少,不需要硬件设备。它不能在同一数据集节点中部署仲裁器。它可以部署在其他应用服务器或监控服务器中,或者部署在单独的虚拟机中。为了确保副本集中有奇数个成员(包括主节点),我们需要将仲裁节点添加到投票中。否则,当主服务器无法运行时,它不会自动切换主服务器。简单理解,我们可以对应用进行总结,请求mons mondb crud操作,配置服务器、数据库和元信息,与mons数据同步,最后以碎片的形式存放(芯片)为了防止在复制数据时失去同步,在仲裁时间芯片存储器中设置存储在一个数据存储器中以决定哪个节点。环境centos6.5的准备系统三台服务器:192.168.0.75/84/ 86安装包:mondb-linux-x86 _ 64-3.4.6。tgz服务器的规划服务器75服务器84服务器86 monmouth配置服务器配置服务器配置服务器配置服务器碎片服务器1主节点碎片服务器1次节点碎片服务器1仲裁碎片服务器2主节点。碎片服务器2次节点碎片服务器3次节点碎片服务器3仲裁碎片服务器3主节点端口配置:mons:20000配置:21000 shard 1 : 27001 shard 2 : 27002 shard 3 : 27003楼群1。安装mondb #真空tar xzvfmondb-linux-x86 _ 64-3.4.6.tgzc/usr/local/#改名为mondb-linux-x86 _ 64-3 . 4 . 6 mond bmv。在这六个目录中,mons、configuration、shard1、shard2和shard3都构建在每台机器上,因为mons。mkdir-p/usr///conf mondb local mkdir-p/usr//local mondb mons/log mkdir-p/usr/local/mondb/configuration/data mkdir-p/usr///configuration/log mkdir-p/usr///local monds hard 1/data mkdir-p/usr//local monds hard 1/log mkdir-p/usr//local monds hard 2/data mkdir-p/usr//local monds hard 2/log mkdir-p/usr///localbucket =: $ path immediate # source 2,configuration server configuration server在mondb3.4中,configuration server需要创建副本集,否则群集不成功。添加配置文件vi/usr//local mondb conf/config . conf # #配置文件pid file path =/usr///配置local mondb//config srv . pid log mdb =/usr///local mondb配置/数据log path =/usr///配置local mondb//congigsrv . log log log append = true bind _ ip = 0 . 0 . 0 . 0 . 0 port = 21000 fork = true #声明这是一个集群配置数据库;configsvr = real name #副本集replset = configuration #设置最大连接数maxconns = 20000启动配置服务器mond-f/usr///local mondb conf/config . conf登录任意配置服务器并初始化配置副本集#连接端口21000 #配置变量configuration {{…_id:配置成员:{… {_ id: 0,版主:192 . 168 . 0 . 75 : 21000 },… {_ id和成员节点。3.配置分段副本集(三台机器)。设置第一个分段副本集配置文件6/usr//local mondb conf/shard 1 . conf #配置文件#-—pid file path =/usr///local mondb shard 1//shard 1 . pid log mdb =/usr///local mondb shard 1/data log path =/usr///local mondb shard 1//shard 1 . log log log append = true bind _ ip = 0 . 0 . 0 . 0 . 0 port = 27001 fork = true。# openweb monitoring http interface = true rest = true name # replica set repl set = shard 1 #声明这是一个集群的共享数据库;shardsvr = true #设置maxconns = 20000 shard1服务器的最大连接数。三台服务器启动mond-f/usr///local mondb conf/shard 1 . conf登录任意服务器并初始化使用副本集端口27001管理数据库#使用management #定义副本集的配置。第三节点的arbiteronly:真正表示仲裁节点。配置{{{…_id:shard1成员:{… {_ id: 0,版主:192 . 168 . 0 . 75 : 27001 },… {_ id: 1,版主:192.168.0.84 echo 3-@版主:192.168.0.86:27001,arbitor only:true } }…}…}…配置初始化#副本集rs.initiate (config设置第二个段副本集配置文件vi/usr//local mondb conf/shard 2 . conf #配置文件#-—pid file path =/usr///local mondb shard 2//shard 2 . pid log mdb =/usr///local mondb shard 2/data log path =/usr///local mondb shard 2//shard 2 . log logappend = true bind _ ip = 0 . 0 . 0 . 0 . 0 port = 27002 fork = true #打开网络监控http interface = true rest = true name #副本集 设置最大连接数maxconns = 20000 shard2服务器三台服务器启动mond-f/usr///local mondb conf/shard 2 . conf登录任意服务器并初始化使用副本集端口27002管理数据库#使用管理#定义复制配置设置配置{{{…_id:shard2成员:{… {_ id: 0。0.75 :27002...{_ id: 1,版主:192 . 168 . 0 . 84 : 27002 },...{_ id: 2,版主:192.168.0.86 echo 3-@ 。设置第三个分段副本集配置文件vi/usr//local mondb conf/shard 3 . conf #配置文件#-—pidfilepath =/usr///local mondb shard 3//shard 3 . pid log mdb =/usr///local mondb shard 3/data log path =/usr///local mondb shard 3//shard 3 . log log append = true bind _ ip = 0 . 0 . 0 . 0 . 0 port = 27003 fork = true #开放网络监控http interface = true rest = true name #副本集shardsvr = true #设置最大连接数maxconns = 20000 shard3服务器三台服务器启动mond-f/usr///local mondb conf/shard 3 . conf登录任意服务器并初始化使用副本集端口27003管理数据库#使用管理#定义复制配置设置配置{{…_id:shard3成员:{{_ id: 0,版主:192 . 168 . 0 . 75 : 27003 },{版主:192 . 168 . 0 . 86 : 27003 } }……配置初始化#副本集rs . initiate(config);4。配置路由服务器mons。首先启动配置服务器和分区服务器,然后启动路由实例启动路由实例:(三台机器)6/usr//local mond dbconf/mons . conf # content pid file path =/usr///local mond bmons//mons . pid log path =/usr///local mondb。mons//mons . log logappend = true bind _ ip = 0 . 0 . 0 . 0 port = 20000 fork = true # monitor配置服务器,只有1或3份配置可用于配置服务器设置名称。configdb = configuration/192 . 168 . 0 . 75 : 21000192 . 168 . 0 . 84 : 21000192 . 168 . 0 . 86 : 21000 #设置最大连接数maxconns = 20000个mons服务器。三个服务器启动mond-f/usr///local mond bconf/mons . conf . v目前已经建立了mondb配置服务器和路由服务器,并且建立了所有的碎片服务器。然而,应用程序是连接到mons路由服务器和碎片机制可以 t被使用,因此在程序中有效地建立芯片配置是必要的。登录任意monsport 20000管理数据库使用#用户管理#系列路由的副本服务器分发sh . addshard(shard 1/192 . 168 . 0 . 75 : 27001192 . 168 . 0 . 84 : 27001192 . 168 . 0 . 86 : 27001)sh . addshard(shard 2/192.168目前,在测试,配置服务、路由服务、碎片服务和复制服务都是串联的,但我们的目标是自动划分数据。连接到mons中的指定数据库,并准备允许指定的集合片段生效。#指定碾压效果db . run command({ enable sharding:library });#指定数据库需要收集和关键层db . run command({ shard collection:wh测试分段配置结果my 127.0.0.1:20000使用#用法库;#插入测试数据(var i = 1;;我100000;i) db.table1.save({ number: me,test1:test val 1 });#视图划分如下,一些无关信息保存在db . table 1 . stats;{slice:真,ns:哪里。表1 count: 100000,numextents :13,size: 5600000,storagesize :22372352,totalindexsize :6213760,索引大小:{_ id _: 3335808,id_1 :2877952},avb jsize。表1 count: 42183,size: 0,… ok: 1},shard2 :{ ns: where。表1计数:38937,大小:2180472,… ok: 1},shard3 :{ ns: where。表1 count: 18880,size: 3419528,… ok:1}},ok:1}可以看出数据分为三段,其中每个shard1 count: 42183,shard2 count: 38937,shard3 count: 18880。成功了!运维开始按照mondb的启动顺序启动配置服务器。首先,启动芯片,启动mons。mond-f/usr//local mondb conf/config . conf mond-f/usr//local mondb conf/shard 1 . conf mond-f/usr//local mondb conf/shard 2 . conf mond-f/usr//local mondb conf/shard 3 . conf mond-f/usr///local mondb conf/mons . conf关闭时,kills直接杀死所有进程。killall mond killall mons总结这就是本文的全部内容。希望这篇文章的内容能给你的学习或者工作带来一些帮助。有问题可以留言。谢谢你的支持。保持住。参考uff1a (iv) - mondb碎片构建高可用性集群mondb3.4复制集群构建mondb(iv)-碎片的高可用性集群
了解更多mongo副本集构造(mongodb副本集和分片哪个好)相关内容请关注本站点。