




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
MongoDB 集群帮助手册集群帮助手册 2016 年年 5 月月 修订记录 版本版本修订说明修订说明作者作者审核审核审核日期审核日期 V1 0MongoDB 集群帮助手册 一一 Mongodb 集集群群架架构构简简介介 这是一种可以水平扩展的模式 在数据量很大时特给力 实际大规模应用一般会采用这种 架构去构建 monodb 系统 要构建一个 MongoDB Sharding Cluster 需要三种角色 Shard Server mongod 实例 用于存储实际的数据块 实际生产环境中一个 shard server 角色可由几台机器组个一个 relica set 承担 防止主机单点故障 Config Server mongod 实例 存储了整个 Cluster Metadata 其中包括 chunk 信 息 Route Server mongos 实例 前端路由 客户端由此接入 且让整个集群看上去像 单一数据库 前端应用可以透明使用 本例架构示例图 1 分别在 3 台机器运行一个 mongod 实例 称为 mongod shard11 mongod shard12 mongod shard13 组织 replica set1 作为 cluster 的 shard1 2 分别在 3 台机器运行一个 mongod 实例 称为 mongod shard21 mongod shard22 mongod shard23 组织 replica set2 作为 cluster 的 shard2 3 每台机器运行一个 mongod 实例 作为 3 个 config server 4 每台机器运行一个 mongs 进程 用于客户端连接 主机主机 IP端口信息端口信息 Server110 1 1 1mongod shard11 27017 mongod shard12 27018 mongod config1 20000 mongs1 30000 Server210 1 1 2mongod shard12 27017 mongod shard22 27018 mongod config2 20000 mongs2 30000 Server310 1 1 3mongod shard13 27017 mongod shard23 27018 mongod config3 20000 mongs3 30000 二二 集集群群配配置置 2 1 软件准备软件准备 1 安装 monodb 软件 su mongodb tar zxvf mongodb linux x86 64 1 6 2 tar 创建数据目录 根据本例 sharding 架构图所示 在各台 sever 上创建 shard 数据文件目录 Server1 su monodb cd monodb mkdir p data shard11 mkdir p data shard21 Server2 su monodb cd monodb mkdir p data shard11 mkdir p data shard22 Server3 su monodb cd monodb mkdir p data shard13 mkdir p data shard23 2 2 配置配置 relica sets 复制集 复制集 1 配置 shard1 所用到的 replica sets Server1 cd mongodb mongodb linux x86 64 1 6 2 bin mongod shardsvr replSet shard1 port 27017 dbpath mongodb data shard11 oplogSize 100 logpath mongodb data shard11 log logappend fork Server2 cd mongodb mongodb linux x86 64 1 6 2 bin mongod shardsvr replSet shard1 port 27017 dbpath mongodb data shard12 oplogSize 100 logpath mongodb data shard12 log logappend fork Server3 cd mongodb mongodb linux x86 64 1 6 2 bin mongod shardsvr replSet shard1 port 27017 dbpath mongodb data shard13 oplogSize 100 logpath mongodb data shard13 log logappend fork 初始化 replica set 用 mongo 连接其中一个 mongod 执行 config id shard1 members id 0 host 10 1 1 1 27017 id 1 host 10 1 1 2 27017 id 2 host 10 1 1 3 27017 rs initiate config 同样方法 配置 shard2 用到的 replica sets server1 cd mongodb mongodb linux x86 64 1 6 2 bin mongod shardsvr replSet shard2 port 27018 dbpath mongodb data shard21 oplogSize 100 logpath mongodb data shard21 log logappend fork server2 cd mongodb mongodb linux x86 64 1 6 2 bin mongod shardsvr replSet shard2 port 27018 dbpath mongodb data shard22 oplogSize 100 logpath mongodb data shard22 log logappend fork server3 cd mongodb mongodb linux x86 64 1 6 2 bin mongod shardsvr replSet shard2 port 27018 dbpath mongodb data shard23 oplogSize 100 logpath mongodb data shard23 log logappend fork 初始化 replica set 用 mongo 连接其中一个 mongod 执行 config id shard2 members id 0 host 10 1 1 1 27018 id 1 host 10 1 1 2 27018 id 2 host 10 1 1 3 27018 rs initiate config 到此就配置好了二个 replica sets 也就是准备好了二个 shards 2 3 配置三台配置三台 config server Server1 mkdir p mongodb data config mongod configsvr dbpath mongodb data config port 20000 logpath mongodb data config log logappend fork config server 也需要 dbpath Server2 mkdir p mongodb data config mongod configsvr dbpath mongodb data config port 20000 logpath mongodb data config log logappend fork Server3 mkdir p mongodb data config mongod configsvr dbpath mongodb data config port 20000 logpath mongodb data config log logappend fork 2 4 配置配置 mongs 在 server1 server2 server3 上分别执行 mongos configdb 10 1 1 1 20000 10 1 1 2 20000 10 1 1 3 20000 port 30000 chunkSize 5 logpath mongodb data mongos log logappend fork mongs 不需要 dbpath 2 5 添加复制集添加复制集 连接到其中一个 mongos 进程 并切换到 admin 数据库做以下配置 1 连接到 mongs 并切换到 admin mongo 10 1 1 1 30000 admin db Admin 2 加入 shards 如里 shard 是单台服务器 用 db runCommand addshard 这 样的命令加入 如果 shard 是 replica sets 用 replicaSetName port serverhostname2 port 这样的格式表示 例如本例执行 db runCommand addshard shard1 10 1 1 1 27017 10 1 1 2 27017 10 1 1 3 27017 name s1 maxsize 20480 db runCommand addshard shard2 10 1 1 1 27018 10 1 1 2 27018 10 1 1 3 27018 name s2 maxsize 20480 注意 在添加第二个 shard 时 出现 error test database 已经存在的错误 这里用 mongo 命令连接 到第二个 replica set 用 db dropDatabase 命令把 test 数据库给删除然后就可加入 3 可选参数 Name 用于指定每个 shard 的名字 不指定的话系统将自动分配 maxSize 指定各个 shard 可使用的最大磁盘空间 单位 megabytes 4 Listing shards db runCommand listshards 1 如果列出了以上二个你加的 shards 表示 shards 已经配置成功 5 2 6 数据库分片以及数据库分片以及 Collecton 分片分片 1 激活数据库分片 命令 db runCommand enablesharding 通过执行以上命令 可以让数据库跨 shard 如果不执行这步 数据库只会存放在一个 shard 一旦 激活数据库分片 数据库中不同的 collection 将被存放在不同的 shard 上 但一个 collection 仍旧存放 在同一个 shard 上 要使单个 collection 也分片 还需单独对 collection 作些操作 2 Collection 分片 要使单个 collection 也分片存储 需要给 collection 指定一个分片 key 通过以下命令操作 db runCommand shardcollection key 注 a 分片的 collection 系统会自动创建一个索引 也可用户提前创建好 b 分片的 collection 只能有一个在分片 key 上的唯一索引 其它唯一索引不被允许 One note a sharded collection can have only one unique index which must exist on the shard key No other unique indexes can exist on the collection 2 7 分片分片 collection 例子例子 db runCommand shardcollection test c1 key id 1 for var i 1 i db c1 stats 该命令可以查看表的存储状态 2 8 Mongodb 运行时添加节点运行时添加节点 1 查看复制集节点配置 mongo 192 168 1 207 27017 rs0 PRIMARY rs conf id rs0 version 3 members id 0 host 192 168 1 207 27017 id 1 host 192 168 1 207 27018 2 添加节点 添加新的数据目录 mkdir p mongodb data shard4 启动节点 mongod shardsvr replSet shard1 port 27019 dbpath mongodb data shard4 oplogSize 100 logpath mongodb data shard4 log logappend fork 连接主节点 mongo 192 168 1 207 27017 rs0 PRIMARY rs isMaster setName rs0 ismaster true secondary false hosts 192 168 1 207 27017 192 168 1 207 27018 primary 192 168 1 207 27017 me 192 168 1 207 27018 maxBsonObjectSize 16777216 localTime ISODate 2013 05 22T13 04 36 501Z ok 1 添加节点 rs0 PRIMARY rs add 192 168 1 207 27019 ok 1 3 再次查看状态 rs0 PRIMARY rs conf id rs0 version 3 members id 0 host 192 168 1 207 27017 id 1 host 192 168 1 207 27018 id 1 host 192 168 1 207 27019 添加成功 2 9 Mongodb 运行时移除节点运行时移除节点 其他步骤同上 其中只是将添加命令改为移除命令 rs0 PRIMARY rs remove 192 168 1 207 27019 最后还需要关掉 192 168 1 207 27019 该服务 Ps ef grep mongo 查找该服务 然后通过 kill 9 pid 关闭服务 2 10 Mongodb 运行时移除分片运行时移除分片 1 连接 mongos 节点 mongo 192
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 安置期房买卖合同(标准版)
- 专业培训服务合同协议书要求
- 药厂生产管理培训课件
- 乡村社区特色种植推广合同
- 项目需求分解及风险管理清单模板
- 雨中风景300字(7篇)
- 建筑工程施工材料采购及质量保证协议
- 汉字文化学习课程
- 完璧归赵缩写150字(10篇)
- 诗词名句积累与应用教学设计
- 2025年发展对象培训班考试试题及答案
- 院前急救知识考核试题及答案
- 河湖水生态产品价值核算与实现机制的研究进展
- 孤立性血管性眩晕
- 绿色金融培训课件
- 牛奶加工工艺流程
- 问题性皮肤培训课件
- 2025年工业区污水处理厂可行性研究报告
- 2024年婴幼儿托育服务与管理专业人才培养方案调研报告
- 特色农产品电商直播基地建设项目可行性研究报告
- 2024-2025学年人教版数学八年级下册期末复习卷(含解析)
评论
0/150
提交评论