ddtv.space index.php,图解MongoDB原理(二)
根据上篇文章《图解MongoDB原理》的基本介绍,本文以具体的操作为例继续深入解析mongodb。 演示的所有服务都是在一台机器上,我的目录是F:\JAVA\MongoDB\cluster,文件结构如下: 说明:1个配置服务结点,1个路由服务结点,三个分片结点。 vcD4KPHA+PHN0cm9u
根据上篇文章《图解MongoDB原理》的基本介绍,本文以具体的操作为例继续深入解析mongodb。
演示的所有服务都是在一台机器上,我的目录是F:\JAVA\MongoDB\cluster,文件结构如下:
说明:1个配置服务结点,1个路由服务结点,三个分片结点。
喎?http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PHN0cm9uZz7G9LavwfezzDwvc3Ryb25nPjwvcD4KPHA+MaGixvS2r2NvbmZpZ7f+zvE8L3A+CjxwPkY6XEpBVkFcTW9uZ29EQlxjbHVzdGVyXG1vbmdvXG1vbmdvZCAtY29uZmlnc3ZyIC1kYnBhdGggRjpcSkFWQVxNb25nb0RCXGNsdXN0ZXJcZGF0YVxjb25maWcgLXBvcnQgMjAwMDAgLXJlc3Q8L3A+CjxwPjKhosb0tq9tb25nb3O3/s7xPC9wPgo8cD5GOlxKQVZBXE1vbmdvREJcY2x1c3Rlclxtb25nb1xtb25nb3MgLWNvbmZpZ2RiIDEyNy4wLjAuMToyMDAwMCAtcG9ydCAzMDAwMCAtY2h1bmtTaXplIDU8L3A+CjxwPjOhosb0tq/L+dPQt9bGrLf+zvE8L3A+CjxwPkY6XEpBVkFcTW9uZ29EQlxjbHVzdGVyXG1vbmdvXG1vbmdvZCAtc2hhcmRzdnIgLW1hc3RlciAtcG9ydCAyNzAwMSAtZGJwYXRoIEY6XEpBVkFcTW9uZ29EQlxjbHVzdGVyXGRhdGFcc2hhcmQxIC1sb2dwYXRoIEY6XEpBVkFcTW9uZ29EQlxjbHVzdGVyXGRhdGFcc2hhcmQxXGxvZyAtbG9nYXBwZW5kPGJyPgo8YnI+CkY6XEpBVkFcTW9uZ29EQlxjbHVzdGVyXG1vb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JnF1b3Q7JGVyciZxdW90OyA6ICZxdW90O2Vycm9yIGNyZWF0aW5nIGluaXRpYWwgZGF0YWJhc2UgY29uZmlnIGluZm9ybWF0aW9uIDo6IGNhdXNlZCBiPGJyPgp5IDo6IGNhbg=="t find a shard to put new db on",
"code" : 10185
} at src/mongo/shell/query.js:128
删除分片时上个任务未完成时报错:
mongos> db.runCommand({removeshard:"127.0.0.1:27032"})
{ "ok" : 0, "errmsg" : "Can't have more than one draining shard at a time" }
MongoVUE连接测试
连接界面如下:
查看分片:
每个chunk 的大小(size)(单位为MB):
单个分片存储数据效果:
增加分片shard2和shard3后的Balancer操作过程:
分片后的数据:
查看所有的数据库,其中partitioned为True表示这个数据库设置了分片。
config数据库的结构:
查看服务状态,可以看到MongoDB支持的最大连接数为20000:
mongod启动参数
当启动参数报错时会有提示,还有参数的英文解释:
General options:
-h [ --help ] show this usage information
--version show version information
-f [ --config ] arg configuration file specifying additional options
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
--quiet quieter output
--port arg specify port number - 27017 by default
--bind_ip arg comma separated list of ip addresses to listen on
- all local ips by default
--maxConns arg max number of simultaneous connections - 20000 by
default
--logpath arg log file to send write to instead of stdout - has
to be a file, not directory
--logappend append to logpath instead of over-writing
--pidfilepath arg full path to pidfile (if not set, no pidfile is
created)
--keyFile arg private key for cluster authentication
--setParameter arg Set a configurable parameter
--auth run with security
--cpu periodically show cpu and iowait utilization
--dbpath arg directory for datafiles - defaults to \data\db\
--diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads
--directoryperdb each database will be stored in a separate
directory
--ipv6 enable IPv6 support (disabled by default)
--journal enable journaling
--journalCommitInterval arg how often to group/batch commit (ms)
--journalOptions arg journal diagnostic options
--jsonp allow JSONP access via http (has security
implications)
--noauth run without security
--nohttpinterface disable http interface
--nojournal disable journaling (journaling is on by default
for 64 bit)
--noprealloc disable data file preallocation - will often hurt
performance
--noscripting disable scripting engine
--notablescan do not allow table scans
--nssize arg (=16) .ns file size (in MB) for new databases
--profile arg 0=off 1=slow, 2=all
--quota limits each database to a certain number of files
(8 default)
--quotaFiles arg number of files allowed per db, requires --quota
--repair run repair on all dbs
--repairpath arg root directory for repair files - defaults to
dbpath
--rest turn on simple rest api
--slowms arg (=100) value of slow for profile and console log
--smallfiles use a smaller default file size
--syncdelay arg (=60) seconds between disk syncs (0=never, but not
recommended)
--sysinfo print some diagnostic system information
--upgrade upgrade db if needed
Windows Service Control Manager options:
--install install Windows service
--remove remove Windows service
--reinstall reinstall Windows service (equivalent to --remove
followed by --install)
--serviceName arg Windows service name
--serviceDisplayName arg Windows service display name
--serviceDescription arg Windows service description
--serviceUser arg account for service execution
--servicePassword arg password used to authenticate serviceUser
Replication options:
--oplogSize arg size to use (in MB) for replication op log. default is
5% of disk space (i.e. large is good)
Master/slave options (old; use replica sets instead):
--master master mode
--slave slave mode
--source arg when slave: specify master as --only arg when slave: specify a single database to replicate
--slavedelay arg specify delay (in seconds) to be used when applying
master ops to slave
--autoresync automatically resync if slave data is stale
Replica set options:
--replSet arg arg is [/]
--replIndexPrefetch arg specify index prefetching behavior (if secondary)
[none"_id_only|all]
Sharding options:
--configsvr declare this is a config db of a cluster; default port
27019; default dir /data/configdb
--shardsvr declare this is a shard db of a cluster; default port
27018
mongos启动参数
General options:
-h [ --help ] show this usage information
--version show version information
-f [ --config ] arg configuration file specifying additional options
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
--quiet quieter output
--port arg specify port number - 27017 by default
--bind_ip arg comma separated list of ip addresses to listen on - all
local ips by default
--maxConns arg max number of simultaneous connections - 20000 by
default
--logpath arg log file to send write to instead of stdout - has to be
a file, not directory
--logappend append to logpath instead of over-writing
--pidfilepath arg full path to pidfile (if not set, no pidfile is
created)
--keyFile arg private key for cluster authentication
--setParameter arg Set a configurable parameter
--nohttpinterface disable http interface
Windows Service Control Manager options:
--install install Windows service
--remove remove Windows service
--reinstall reinstall Windows service (equivalent to --remove
followed by --install)
--serviceName arg Windows service name
--serviceDisplayName arg Windows service display name
--serviceDescription arg Windows service description
--serviceUser arg account for service execution
--servicePassword arg password used to authenticate serviceUser
Sharding options:
--configdb arg 1 or 3 comma separated config servers
--localThreshold arg ping time (in ms) for a node to be considered local
(default 15ms)
--test just run unit tests
--upgrade upgrade meta data version
--chunkSize arg maximum amount of data per chunk
--ipv6 enable IPv6 support (disabled by default)
--jsonp allow JSONP access via http (has security implications)
--noscripting disable scripting engine
分片+主从安装命令
主从的部署是不具有故障自动转移功能的,而复本集的部署支持故障转移。
主数据结点:
mongod -shardsvr -master -port 27001 -dbpath F:\JAVA\MongoDB\cluster\shard\data
从数据结点:
mongod -shardsvr -slave -source 127.0.0.1:27001 -port 27002 -dbpath F:\JAVA\MongoDB\cluster\shards\data
分片+复本集安装
复本集安装要对每个分片进行设置,用mongo直接连接分片,执行rs.initiate(cfg)进行设置,设置好后需要分别将每个分片加入config中。相关的函数有:
rs.status() { replSetGetStatus : 1 } checks repl set status
rs.initiate() { replSetInitiate : null } initiates set with default settings
rs.initiate(cfg) { replSetInitiate : cfg } initiates setwith configuration cfg
rs.conf() get the current configuration object from local.system.replset
rs.reconfig(cfg) updates the configuration of a running replica set with cfg (disconnects)
rs.add(hostportstr) add a new member to the set with default attributes (disconnects)
rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)
rs.addArb(hostportstr) add a new member which is arbiterOnly:true (disconnects)
rs.stepDown([secs]) step down as primary (momentarily) (disconnects)
rs.syncFrom(hostportstr) make a secondary to sync from the givenmember
rs.freeze(secs) make a node ineligible to become primary for the time specified
rs.remove(hostportstr) remove a host from the replica set (disconnects)
rs.slaveOk() shorthand for db.getMongo().setSlaveOk()
启动命令
路由结点:
mongos -configdb 127.0.0.1:20000 -port 30000 -chunkSize 5
配置结点:
mongod -configsvr -dbpath F:\JAVA\MongoDB\cluster\config\data -port 20000 -rest
分片1:
mongod -shardsvr -replSet shard1/127.0.0.1:27051,127.0.0.1:27041 -port 27031 -dbpath F:\JAVA\MongoDB\cluster\repa_shard1\data
分片1复本集b:
mongod -shardsvr -replSet shard1/127.0.0.1:27051 -port 27041 -dbpath F:\JAVA\MongoDB\cluster\repb_shard1\data
分片1复本集c:
mongod -shardsvr -replSet shard1/127.0.0.1:27041 -port 27051 -dbpath F:\JAVA\MongoDB\cluster\repc_shard1\data
分片2:
mongod -shardsvr -replSet shard2/127.0.0.1:27052,127.0.0.1:27042 -port 27032 -dbpath F:\JAVA\MongoDB\cluster\repa_shard2\data
分片2复本集b:
mongod -shardsvr -replSet shard2/127.0.0.1:27052 -port 27042 -dbpath F:\JAVA\MongoDB\cluster\repb_shard2\data
分片2复本集c:
mongod -shardsvr -replSet shard2/127.0.0.1:27042 -port 27052 -dbpath F:\JAVA\MongoDB\cluster\repc_shard2\data
WEB控制台
分片服务与配置服务的mongod加上-rest后会有web控制台,具体的地址在启动输出中会有,如下
本文原创发布php中文网,转载请注明出处,感谢您的尊重!
ddtv.space index.php,图解MongoDB原理(二)相关推荐
- Android10.0 Binder通信原理(二)-Binder入门篇
摘要:本节主要来讲解Android10.0 Binder的设计原理,如何设计一个Binder通信 阅读本文大约需要花费15分钟. 文章首发微信公众号:IngresGe 专注于Android系统级源码分 ...
- (转) 一张图解AlphaGo原理及弱点
一张图解AlphaGo原理及弱点 2016-03-23 郑宇,张钧波 CKDD 作者简介: 郑宇,博士, Editor-in-Chief of ACM Transactions on Intellig ...
- 图解LinkedHashMap原理
1 前言 LinkedHashMap继承于HashMap,如果对HashMap原理还不清楚的同学,请先看上一篇:图解HashMap原理 2 LinkedHashMap使用与实现 先来一张LinkedH ...
- 图解elasticsearch原理转载自
转载自 图解elasticsearch原理 版本 elasticsearch版本: elasticsearch-2.x 内容 图解ElasticSearch 云上的集群 集群里的盒子 云里面的每个白 ...
- MongoDB 教程二: 添加, 删除,查询 shell命令
视频:MongoDB 教程二: 添加, 删除,查询 shell命令 MongoDB Shell 常用操作命令 MonoDB shell命令操作语法和JavaScript很类似,其实控制台底层的查询 ...
- 图解通信原理与案例分析-19:3G CDMA码分多址通信技术原理---码分多址、OVSF正交扩频码、伪随机码序列
前言导读: 码分多址(CDMA)是第三代移动通信的核心技术,其基本思想是在相同的载波频段上,通过的不同的地址码来区分的不同用户.不同基站的数据. 3G CDMA与2G GSM通信相比,主要网络架构与通 ...
- mysql新增列并同时增加数据_图解MySQL | [原理解析] MySQL 为表添加列 是怎么quot;立刻quot;完成的...
在上一期图解 图解MySQL | MySQL DDL为什么成本高?中,我们介绍了: 传统情况下,为表添加列需要对表进行重建 腾讯团队为 MySQL 引入了 Instant Add Column 的方案 ...
- 音视频开发( 34)---麦克风阵列原理二
麦克风阵列原理二 1 麦克风阵列 麦克风阵列,是一组位于空间不同位置的全向麦克风按一定的形状规则布置形成的阵列,是对空间传播声音信号进行空间采样的一种装置,采集到的信号包含了其空间位置信息.根据声源和 ...
- mysql新增字段位置_图解MySQL | [原理解析] MySQL 为表添加列 是怎么quot;立刻quot;完成的...
在上一期图解 图解MySQL | MySQL DDL为什么成本高?中,我们介绍了: 传统情况下,为表添加列需要对表进行重建 腾讯团队为 MySQL 引入了 Instant Add Column 的方案 ...
最新文章
- 如果你是C开发人员请看这三个显式编程技巧
- 送你6份最新开源代码!含NLP、ML、计算机视觉方向(附代码论文)
- 读书笔记之《Windows内核原理与实现》
- 电子工程系庆贺电贺信_创造下一代光电子集成电路
- Python学习笔记7:函数对象及函数对象作參数
- java服务器端分页_使用数据表的服务器端分页
- 进程间的六种通信方式
- 项目工程自动化 - OCLint
- 如何判定耿耿数已经被bind过?
- [已修正]安装struts找不到tld文件
- ubuntu16.04安装驱动
- 教你开发一个JS代码加密工具
- 甲骨文大裁员,竟是因为它?
- Maven Assembly插件介绍
- python研究生导师_导师想要什么样的心理学研究生?
- 外挂的介绍 什么是外挂
- 淘宝flexible.js+rem适配pc端
- 【Docker】如何进入到Docker容器内部
- 关于滑轮组的计算机知识点,计算机试题第一套.docx
- 文学-谚语-英文谚语:英文谚语
热门文章
- 【金融】新成立基金建仓时点、行业分布与市场行情关系探究
- SAP那些事-职业篇-35-PA考试通过啦
- Computing Trajectory Similarity in Linear Time: A Generic Seed-Guided Neural Metric Learning Appr...
- poj 1830 高斯消元
- 汉语编程联姻大中院校
- 第八周---FPGA流水灯显示和串口循环输出实验
- SYN480R模块解码EV1527教程
- JS移动客户端--触屏滑动事件
- Oracle 恢复dmp文件到数据库表中(超大DMP) 【数据系列 3】
- 分布式系统的冰与火与技术栈