Mongodb安装

Linux版本:CentOS release 6.9

Mongodb版本:mongodb-linux-x86_64-3.6.1.tgz

示例是在一台主机上安装mongodb集群

端口

路由进程mongo

20001

20002

20003

配置服务器config

20011

20012

20013

分片服务器shard1

20031

20032

20033

分片服务器shard2

20041

20042

20043

1、解压文件

执行解压命令:tar -zxvf mongodb-linux-x86_64-3.6.1.tgz

2、创建数据,日志目录,结构如下 在同台机器创建三主三从三配置三路由架构cp001,cp002,cp003目录结构均一样

3、

1、配置文件

dbpath数据存放位置

logpath日志文件位置

pidfilepath进程号存放位置

port端口号

fork是否后台运行

replSet副本集名称

configdb监听的配置服务器,只能有1个或者3个 configs为配置服务器的副本集名字

1)mongo配置服务器的配置

2)mongo路由服务器配置

3)shard1配置

4)shard2配置

4、启动Mongodb

1)启动配置

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp001/conf/config.conf

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp002/conf/config.conf

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp003/conf/config.conf

2)启动复制集

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp001/conf/shard1.conf

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp002/conf/shard1.conf

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp003/conf/shard1.conf

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp001/conf/shard2.conf

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp002/conf/shard2.conf

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp003/conf/shard2.conf

3)启动路由

/jq/mongodb-linux-x86_64-3.6.1/bin/mongos -f /jq/cp001/conf/mongos.conf

*由于是同一台主机,只执行一个配置

5、登陆任意一个config server节点,配置副本集

/jq/mongodb-linux-x86_64-3.6.1/bin/mongo --port 20011

#设置变量  这里的id号,要和配置文件中的副本集名称相同

config = {

_id : "configs",

members : [

{_id : 0, host : "127.0.0.1:20011" },

{_id : 1, host : "127.0.0.1:20012" },

{_id : 2, host : "127.0.0.1:20013" }

]

}

#初始化副本集

rs.initiate(config)

6、配置shard

1)配置shard1,进入任意一个shard1节点

/jq/mongodb-linux-x86_64-3.6.1/bin/mongo --port 20031

#设置变量

config = {

_id : "shard1",

members : [

{_id : 0, host : "127.0.0.1:20031" },

{_id : 1, host : "127.0.0.1:20032" },

{_id : 2, host : "127.0.0.1:20033" }

]

}

#设置shard1初始化

rs.initiate(config)

2)配置shard2,进入任意一个shard2节点

/jq/mongodb-linux-x86_64-3.6.1/bin/mongo --port 20041

#设置变量

config = {

_id : "shard2",

members : [

{_id : 0, host : "127.0.0.1:20041" },

{_id : 1, host : "127.0.0.1:20042" },

{_id : 2, host : "127.0.0.1:20043" }

]

}

#设置shard2初始化

rs.initiate(config)

7、启用分片

登陆任意一个mongos

/jq/mongodb-linux-x86_64-3.6.1/bin/mongo --port 20001

切换到admin数据库

use admin

串联路由服务器与分配副本集

sh.addShard("shard1/127.0.0.1:20031,127.0.0.1:20032,127.0.0.1:20033")

sh.addShard("shard2/127.0.0.1:20041,127.0.0.1:20042,127.0.0.1:20043")

查看状态

sh.status()

8、测试分片

*不启用分片

use admin

#指定testdb分片生效

db.runCommand( { enablesharding :"testdb"});

#指定数据库里需要分片的集合和片键

db.runCommand( { shardcollection : "testdb.table1",key : {id: 1} } )

for (var i = 1;i<=10000;i++) db.table1.save({id:i,"test1":"item1"}); WriteResult({ "nInserted" : 1 });

#查看状态

db.table1.stats();

*启用分片

use admin

#指定testdb分片生效

db.runCommand( { enablesharding :"testdb2"});

#指定数据库里需要分片的集合和片键

db.runCommand( { shardcollection : "testdb2.table",key : {_id: "hashed"} })

for (var i = 1;i<=10000;i++) db.table.save({id:i,"test1":"item1"}); WriteResult({ "nInserted" : 1 });

#查看状态

db.table1.stats();

停止MongoDB

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp001/conf/config.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp002/conf/config.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp003/conf/config.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp001/conf/shard1.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp002/conf/shard1.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp003/conf/shard1.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp001/conf/shard2.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp002/conf/shard2.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongod -f /jq/cp003/conf/shard2.conf --shutdown

/jq/mongodb-linux-x86_64-3.6.1/bin/mongos -f /jq/cp001/conf/mongos.conf --shutdown

MongoDB 3.6.1集群部署的更多相关文章

  1. mongoDB研究笔记:分片集群部署

    前面几篇文章的分析复制集解决了数据库的备份与自动故障转移,但是围绕数据库的业务中当前还有两个方面的问题变得越来越重要.一是海量数据如何存储?二是如何高效的读写海量数据?尽管复制集也可以实现读写分析,如 ...

  2. Mongodb集群部署ReplicaSet+Sharding -摘自网络

    网上关于三种集群方式的搭建方式很多,都是分开来介绍的.Replica Set (复制集成)主要是做主从库的,但是没法实现负载均衡的效果,真正实现这个的,是Sharding(分片集群),通过数据分布在每 ...

  3. MongoDB DBA 实践6-----MongoDB的分片集群部署

    一.分片 MongoDB使用分片技术来支持大数据集和高吞吐量操作. 1.分片目的 对于单台数据库服务器,庞大的数据量及高吞吐量的应用程序对它而言无疑是个巨大的挑战.频繁的CRUD操作能够耗尽服务器的C ...

  4. mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析、统计功能,此外还支持本地集群部署管理.

    mtools 是由MongoDB 官方工程师实现的一套工具集,可以很快速的日志查询分析.统计功能,此外还支持本地集群部署管理 https://www.cnblogs.com/littleatp/p/9 ...

  5. MongoDB DBA 实践8-----Linux系统Mongodb分片集群部署

    在Linux系统中,主要是使用命令行进行mongodb的分片集群部署 一.先决条件 mongodb安装成功,明确路径, MongoDB的几个路径: /var/lib/mongodb /var/log/ ...

  6. MongoDB分片集群部署方案

    前言 副本集部署是对数据的冗余和增加读请求的处理能力,却不能提高写请求的处理能力:关键问题是随着数据增加,单机硬件配置会成为性能的瓶颈.而分片集群可以很好的解决这一问题,通过水平扩展来提升性能.分片部 ...

  7. 图解MongoDB集群部署原理(3)

    MongoDB的集群部署方案中有三类角色:实际数据存储结点.配置文件存储结点和路由接入结点. 连接的客户端直接与路由结点相连,从配置结点上查询数据,根据查询结果到实际的存储结点上查询和存储数据.Mon ...

  8. Presto集群部署

    前言: 随着大数据的普及,大部分企业的大数据查询与统计渐渐出现瓶颈.虽说存储方面有分布式的HDFS,HBSE,MongoDB等可以应对,但是面对千万级别(1x10^7)界别的数据量查询时,以上组件也不 ...

  9. centos6下redis cluster集群部署过程

    一般来说,redis主从和mysql主从目的差不多,但redis主从配置很简单,主要在从节点配置文件指定主节点ip和端口,比如:slaveof 192.168.10.10 6379,然后启动主从,主从 ...

随机推荐

  1. Java 动态调试技术原理及实践 【基本功】Java动态追踪技术探究

    https://mp.weixin.qq.com/s/ZlNcvwJ_swspifWTLHA92Q https://mp.weixin.qq.com/s/_hSaI5yMvPTWxvFgl-UItA

  2. mac php7.3 安装扩展

    进入到PHP的目录 /bin/pecl install mongodb 其他扩展同理. 另外: Mac brew 安装的php的启动和停止: brew services stop phpbrew se ...

  3. Mybatis源码研究7:缓存的设计和实现

    Mybatis源码研究7:缓存的设计和实现 2014年11月19日 21:02:14 酷酷的糖先森 阅读数:1020   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...

  4. Mysql 插入自增的最大版本号

    有一个需求,在历史表中,一条数据,在最大版本号上进行自增 INSERT Biz_CourseStudyHistory ( contentStudyID, courseWareID, versionNO ...

  5. 快排的时间复杂度O(n) = nlogn计算过程

    转载:https://www.cnblogs.com/javawebsoa/p/3194015.html 本文以快速排序为例,推导了快排的时间复杂度nlogn是如何得来的,其它算法与其类似. 对数据D ...

  6. [LeetCode] 237. Delete Node in a Linked List 删除链表的节点

    Write a function to delete a node (except the tail) in a singly linked list, given only access to th ...

  7. GitLab - 安装并启动GitLab

    1 - GitLab安装 1.1 信息确认 [Anliven@node102 ~]$ uname -a Linux node102 3.10.0-957.el7.x86_64 #1 SMP Thu N ...

  8. SpringBoot+MybatisPlus+MySql 自动生成代码 自动分页

    一.配置 <!-- Mybatis plus --> <dependency> <groupId>com.baomidou</groupId> < ...

  9. Quartus II——工程建立和常用设置

    Quartus ii是针对Altera FPGA的一款EDA软件,在此以一个led闪烁工程来简单说一下基本操作: 一.注意事项 Quartus ii最大的注意事项就一点:工程名称以及工程里面的文件名称 ...

  10. AS3.0频谱-01

    AS3.0频谱系列-01: package fengzi.spectrum { //import fengzi.colors.GetColor; import flash.display.Sprite ...