MongoDB4.0 WINDOWS环境下 副本集、分片部署
部署开始:
创建路径 D:\Program Files\MongoDB\MySet下
config Data log 文件夹
config文件夹下准备配置文件:
分片1的副本集1
- storage:
- dbPath: D:/Program Files/MongoDB/MySet/Data/shard11
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:/Program Files/MongoDB/MySet/log/shard11.log
- net:
- port: 13211
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: shard1
- sharding:
- clusterRole: shardsvr
分片1的副本集2
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\shard12
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\shard12.log
- net:
- port: 13212
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: shard1
- sharding:
- clusterRole: shardsvr
分片1的副本集3
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\shard13
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\shard13.log
- net:
- port: 13213
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: shard1
- sharding:
- clusterRole: shardsvr
分片2的副本集1
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\shard21
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\shard21.log
- net:
- port: 13221
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: shard2
- sharding:
- clusterRole: shardsvr
分片2的副本集2
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\shard22
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\shard22.log
- net:
- port: 13222
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: shard2
- sharding:
- clusterRole: shardsvr
分片2的副本集3
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\shard23
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\shard23.log
- net:
- port: 13223
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: shard2
- sharding:
- clusterRole: shardsvr
配置节点1
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\config1
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\config1.log
- net:
- port: 13201
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: rscfg
- sharding:
- clusterRole: configsvr
配置节点2
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\config2
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\config2.log
- net:
- port: 13202
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: rscfg
- sharding:
- clusterRole: configsvr
配置节点3
- storage:
- dbPath: D:\Program Files\MongoDB\MySet\Data\config3
- journal:
- enabled: true
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\config3.log
- net:
- port: 13203
- bindIp: 192.168.33.52
- replication:
- oplogSizeMB: 10240
- replSetName: rscfg
- sharding:
- clusterRole: configsvr
路由节点
- systemLog:
- destination: file
- logAppend: true
- path: D:\Program Files\MongoDB\MySet\log\route.log
- net:
- port: 13200
- bindIp: 192.168.33.52
- sharding:
- configDB: rscfg/192.168.33.52:13201,192.168.33.52:13202,192.168.33.52:13203
配置文件准备完成,打开一个cmd窗口
切换到mongo的bin路径
cd /d D://
cd D:\Program Files\MongoDB\Server\4.0\bin
找到配置文件地址进行服务的安装,服务名和服务展示名都需要加上,不然会提示服务名已存在,分片11,12,13,21,22,23,配置1,2,3 这9个节点都是由mongod进程寄宿,路由节点由mongos进程寄宿
mongod -config "D:\Program Files\MongoDB\MySet\config\shard11.cfg" --serviceName "MongoDB_Shard11" --install --serviceDisplayName "MongoDB_Shard11"
mongod -config "D:\Program Files\MongoDB\MySet\config\shard12.cfg" --serviceName "MongoDB_Shard12" --install --serviceDisplayName "MongoDB_Shard12"
mongod -config "D:\Program Files\MongoDB\MySet\config\shard13.cfg" --serviceName "MongoDB_Shard13" --install --serviceDisplayName "MongoDB_Shard13"
mongod -config "D:\Program Files\MongoDB\MySet\config\shard21.cfg" --serviceName "MongoDB_Shard21" --install --serviceDisplayName "MongoDB_Shard21"
mongod -config "D:\Program Files\MongoDB\MySet\config\shard22.cfg" --serviceName "MongoDB_Shard22" --install --serviceDisplayName "MongoDB_Shard22"
mongod -config "D:\Program Files\MongoDB\MySet\config\shard23.cfg" --serviceName "MongoDB_Shard23" --install --serviceDisplayName "MongoDB_Shard23"
mongod -config "D:\Program Files\MongoDB\MySet\config\config1.cfg" --serviceName "MongoDB_Config1" --install --serviceDisplayName "MongoDB_Config1"
mongod -config "D:\Program Files\MongoDB\MySet\config\config2.cfg" --serviceName "MongoDB_Config2" --install --serviceDisplayName "MongoDB_Config2"
mongod -config "D:\Program Files\MongoDB\MySet\config\config3.cfg" --serviceName "MongoDB_Config3" --install --serviceDisplayName "MongoDB_Config3"
mongos -config "D:\Program Files\MongoDB\MySet\config\route.cfg" --serviceName "MongoDB_Route" --install --serviceDisplayName "MongoDB_Route"
所有节点都安装完成后,找到log文件夹下的log文件,如果出现提示,当前可以使用命令行“XXXXX”启动服务,那就成功安装服务了
开启服务,shard1分片的副本集群
net start MongoDB_Shard11
net start MongoDB_Shard12
net start MongoDB_Shard13
开起之后需要进行初始化以及副本集设置
cd /d D://
cd D:\Program Files\MongoDB\Server\4.0\bin
连接到副本集的任意一个节点
mongo 192.168.33.52:13211
初始化副本集
rs.initiate( {_id : "shard1",members: [{ _id: 0, host: "192.168.33.52:13211" },{ _id: 1, host: "192.168.33.52:13212" },{ _id: 2, host: "192.168.33.52:13213" }]})
查看副本集初始化状态
rs.conf()
查看副本集是否是主节点
db.isMaster()
退出当前查询窗口
exit
shard2副本集相关设置,同上
net start MongoDB_Shard21
net start MongoDB_Shard22
net start MongoDB_Shard23
cd /d D://
cd D:\Program Files\MongoDB\Server\4.0\bin
mongo 192.168.33.52:13221
rs.initiate( {_id : "shard2",members: [{ _id: 0, host: "192.168.33.52:13221" },{ _id: 1, host: "192.168.33.52:13222" },{ _id: 2, host: "192.168.33.52:13223" }]})
rs.conf()
db.isMaster()
//需要读写分离写下面这个(同时代码中设置好ReadPreference.Secondary)
//db.getMongo().setSlaveOk()
exit
配置节点副本集相关设置(新版本的配置节点不能使用mirro模式,需要也形成副本集才能由路由节点调用),同上
net start MongoDB_Config1
net start MongoDB_Config2
net start MongoDB_Config3
cd /d D://
cd D:\Program Files\MongoDB\Server\4.0\bin
mongo 192.168.33.52:13201
rs.initiate( {_id : "rscfg",members: [{ _id: 0, host: "192.168.33.52:13201" },{ _id: 1, host: "192.168.33.52:13202" },{ _id: 2, host: "192.168.33.52:13203" }]})
rs.conf()
db.isMaster()
//需要读写分离写下面这个(同时代码中设置好ReadPreference.Secondary)
//db.getMongo().setSlaveOk()
exit
开启路由节点的服务
net start MongoDB_Route
cd /d D://
cd D:\Program Files\MongoDB\Server\4.0\bin
连接路由节点
mongo 192.168.33.52:13200
配置分片shard1,shard2
use admin
db.runCommand({addshard:"shard1/192.168.33.52:13211,192.168.33.52:13212,192.168.33.52:13213"})
db.runCommand({addshard:"shard2/192.168.33.52:13221,192.168.33.52:13222,192.168.33.52:13223"})
查看一下分片列表,确认分片是否配置成功
db.runCommand({ listshards:1 })
对Monitor库启用分片
db.runCommand({enablesharding:"Monitor"})
对多张表设置片键,片键设置模式为 第一个字段为大粒度的局部字段比如类型、月份,第二个字段为常查询字段,粒度细,能够增加随机度
这里设置的前提为未创建表,设置片键后会自动创建索引,已有表,字段又无索引的会提示错误
db.runCommand( { shardcollection : "Monitor.LoadTable",key : {server_type: 1,time:1}} )
db.runCommand( { shardcollection : "Monitor.LogInfo",key : {server_type: 1,time:1}} )
db.runCommand( { shardcollection : "Monitor.LogError",key : {server_type: 1,time:1}} )
db.runCommand( { shardcollection : "Monitor.RequestLog",key : {server_type: 1,time:1}} )
到此为止配置完成,可连接路由节点使用,未测试failover是否生效
删除服务的语句,预留以防需要重新部署
sc delete MongoDB_Shard11
sc delete MongoDB_Shard12
sc delete MongoDB_Shard13
sc delete MongoDB_Shard21
sc delete MongoDB_Shard22
sc delete MongoDB_Shard23
sc delete MongoDB_Config1
sc delete MongoDB_Config2
sc delete MongoDB_Config3
sc delete MongoDB_Route
停止服务的语句,预留以防需要重新部署
net stop MongoDB_Shard11
net stop MongoDB_Shard12
net stop MongoDB_Shard13
net stop MongoDB_Shard21
net stop MongoDB_Shard22
net stop MongoDB_Shard23
net stop MongoDB_Config1
net stop MongoDB_Config2
net stop MongoDB_Config3
net stop MongoDB_Route
MongoDB4.0 WINDOWS环境下 副本集、分片部署的更多相关文章
- Apache+Tomcat+jk windows环境下的集群部署
记一次在Windows服务器上搭建apatch+tomcat+jk的集群搭建过程,其中也遇到了很多问题,总结一下. 一.准备工作 1.apache-tomcat-7.0.88 2.Apche http ...
- Windows环境下flask+Apache+mod_wsgi部署及爬坑
文章目录 安装python Windows 环境使用virtualenv和virtualenvwrapper 安装mod_wsgi 安装nginx 安装Apache 遇到的坑 安装Apache遇到的坑 ...
- Windows环境下,将Django部署到Apache Web Server
在Windows上部署Django(用mod_wsgi)会出现各种奇怪的问题,现简单记录下配置过程及遇到的错误及解决方法. 环境搭建 ...
- Windows环境下实现Jenkins自动化部署
详见:https://blog.csdn.net/Try_harder_every_day/article/details/79170065 Jenkins自动化部署: 几条具体的思路:1.开发人员将 ...
- Windows环境下使用Apache+mod_wsgi部署webpy
1.安装Python和Apache. 2.安装mod_wsgi后获得wsgi.so,并将wsgi.so放到Apache的modules文件夹下. 3.安装webpy. 4.打开httpd.conf(在 ...
- windows环境下Git的安装部署
一.获取安装包 百度搜索“git”,或者访问git官网:https://git-scm.com/,在首页中点击“downloads”进入下载页面 点击“windows”,获取安装包 二.安装部署 双击 ...
- Windows环境下Android Studio v1.0安装教程
Windows环境下Android Studio v1.0安装教程 准备工具 JDK安装包. 要求:JDK 7以及以上版本. Android Studio安装文件. Windows: exe(包含SD ...
- Mongodb3.0.6副本集+分片学习笔记
一.使用问题记录 1. mongodb3.0.6使用mongostat参数 >./mongostat -h 127.0.0.1:27017 -u root -p 123456 /authenti ...
- Android笔记——Windows环境下Android Studio v1.0安装教程
本文主要讲解Windows环境下Android Studio的安装教程,Mac的Android Studio安装与此类似不在赘述,另外友情提示Windows下的SDK与Mac的SDK是通用的,可以直接 ...
随机推荐
- leetcode python 037 求解数独
import numpy as npimport syssys.setrecursionlimit(1000) #例如这里设置为一百万 def get1(n): if n<3: ...
- Python 从入门到实践 试一试 参考代码
这两天学习Python 看了python从入门到实践的书籍,里面有课后题“试一试” 然后就跟着写了,代码在以下地址,如果需要自取 https://files.cnblogs.com/files/fud ...
- 运维route语法
Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...
- wpf binging(五) 数据的转换与验证
1.数据的验证,有时候需要验证同步的数据是否正常 需要派生一个类 ValidationRule 再把这个类指定给binging 进行验证 在这里如果验证不通过 textbox就会变成红色并且发出警告数 ...
- 今日bug:error: invalid array assignment
错误代码: struct STUD { int ID;//学号 ]; float score; }stud; STUD SS[]; student.open("student.dat&quo ...
- C语言---指针变量详解3
指针可以指向一份普通类型的数据,例如 int.double.char 等,也可以指向一份指针类型的数据,例如 int *.double *.char * 等.如果一个指针指向的是另外一个指针,我们就称 ...
- win10操作系统 安装nodejs报2503错误解决方法
报该错误的原因是由于安装操作没有获得足够的管理权限导致. 在电脑左下角开始菜单[右键]选择"命令提示符(管理员)“ 敲入如下命令 msiexec /package 后面加你nodejs的本机 ...
- Archlinux安装指南~小米笔记本Air 13.3英寸版本
小米笔记本Air 13.3英寸版本,配置为:Intel Core i5-6200U处理器.8GB内存.256GB固态硬盘.NVIDIA GeForce 940MX独立显卡,13.3英寸1920X108 ...
- java 基础代码
/** * Created by y0n on 2017/4/17. * 1.输出控制台传递的默认参数 */public class JavaDay001_1 { public static void ...
- iBATIS typeHandler selectKey
typeHandler 是针对把数据库里面的某列的数据类型转换的应用程序中的数据类型,简单的说就是把 type=>dbType 反之把dbType=>type. 例如数据库某列的内容是l ...