使用一台虚拟机搭建伪分布式的MongoDB集群。集群有六台机器,分成六个副本集,S1,S2,S3,S4,S5,S6,每个副本集分三个节点。同一副本集中的节点有一个主节点,两个从节点,从节点的数据与主节点一致;OS为mongos进程(路由服务器);C为config server(配置服务器),设置了三个配置服务器。熟悉使用MongoDB的增删改查操作。
tar -zxvf /home/syp/mongodb-src-r4.2.6.tar.gz
配置环境变量
vi /etc/profile
export PATH=$PATH:/opt/mongodb/bin
source /etc/profile
新建一个文件夹用来存放配置文件以便我们进行启动集群,这里我在opt文件夹下新建了mongo文件夹,在这个文件夹下又新建了6个文件夹,分别代表不同的机器,每个机器的文件夹下有几个进程就配置几个文件夹用来存储数据。这里的设计如下图:
接下来我们要对这些进程配置启动文件,命名为数字的文件为数据分片的配置文件,命名为C的文件为配置分片的配置文件,命名为OS的配置文件为路由服务器进程的配置文件。这三者的配置文件所要配置的地方有所不同,下面以数据分片的修改为例,对配置不同的地方加以注释。这些文件均放在刚才我们配置的第一级目录下以便启动。
接下来我以配置数据分片的配置文件为例,配置1号机器下的1号进程。
修改日志文件路径:path: /opt/mongo/1/1/mongod.log
修改db文件存储目录的路径:dbPath: /opt/mongo/1/1
修改进程文件路径:pidFilePath: /opt/mongo/1/1/mongod.pid
端口号配置为之前设计好的端口:port: 9011
bindIp修改为0.0.0.0
副本集修改为设计时的名字
集群角色:clusterRole: shardsvr(代表存储数据)如果是配置文件则为configsvr
这样我们就配置好一个进程的配置文件了,但是注意一定要按照上面的格式去编辑配置文件,像sharding之后要有冒号,角色clusterRole要有缩进,代表clusterRole是sharding的一个子参数,同样shardsvr前面也要有空格,这是yum的语法格式。这些只是为了方便我们启动节点,也可以启动时加这些参数,但那样就过显繁琐。
重复以上步骤配置所有进程的配置文件,主要需要改的地方,一是路径,二是端口,三是角色。
但对于OS配置文件需要注意,因为OS就是个路由服务器,无存储,无副本:存储去掉
副本去掉
注意告诉路由配置信息在哪(可任选一个配置副本的路径)
最后配置完毕,文件夹下的结构应该是这样:
使用ps aux|grep mongod查看一下进程,显示如上表示成功。
接下来按照之前设计进行分组:
mongo --port 9011
cfg={
_id:"S1", members:[{
_id:0,host:'192.168.43.101:9011'}, {
_id:1,host:'192.168.43.101:9021'}, {
_id:2,host:'192.168.43.101:9031'}]};
rs.initiate(cfg)
显示如上,则表示成功。同样步骤完成所有的分组。
mongos -f os.conf
mongo --port 9014
告诉mongos我们刚才的分片情况
sh.addShard("S1/192.168.43.101:9011")
sh.addShard("S2/192.168.43.101:9022")
sh.addShard("S3/192.168.43.101:9033")
sh.addShard("S4/192.168.43.101:9043")
sh.addShard("S5/192.168.43.101:9053")
sh.addShard("S6/192.168.43.101:9063")
使用sh.status()命令查看分片情况
以上MongoDB就配置完成了,接下来我们熟悉使用一下这个数据库。
use admin 转换到admin数据库下面
我们现在想建个数据库,并让我的集群为他服务,则要
db.runCommand({
enableSharding:"stumis"})
db.runCommand({
shardCollection:"stumis.students",key:{
"_id":"hashed"}})
可以发现我们的数据库多了一个stumis数据库,并对他启动了数据分片的功能。然后我创建这个数据库下的students集合(文档数据库中多个文档构成集合,没有表的概念),针对id用hash的方式做分片。
首先要转换到stumis数据库下,use stumis
Mongodb支持JavaScript语言,可采用编程方式对数据库进行操作,我们使用for循环向数据库插入数据。
注意语法,可以看出操作十分类似SQL,向students集合中插入多个学生文档,有姓名和年龄属性。
看一下插入结果情况:
db.students.find()
查看一下分片情况db.status()
可以发现数据库stumis的集合students进行了分片,每个S上存了两块。
查询年龄小于20的学生
db.students.find({
age: {
$lt: 20}}).pretty()
将查询结果按年龄倒序排序
db.students.find({
age: {
$lt: 20}}).pretty().sort({
"age":-1})
综上,通过一系列设计与实验,搭建好了mongodb数据库,搭建的过程感觉上确实很麻烦,但是,搭建完成后的使用十分便捷,不仅感受到了文档数据库相对其他数据库而言,灵活查询操作的强大功能,又拥有JavaScript编程式的操作支持。
将数据分片的配置文件给出样例:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
#!!!
path: /opt/mongo/1/1/mongod.log
# Where and how to store data.
storage:
#!!!
dbPath: /opt/mongo/1/1
journal:
enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
#!!!
pidFilePath: /opt/mongo/1/1/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
#!!!
port: 9011
#!!!
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
replication:
#!!!
replSetName: S1
sharding:
#!!!
clusterRole: shardsvr
## Enterprise-Only Options
#auditLog:
#snmp:
将OS路由配置文件样例给出如下:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
#!!!
path: /opt/mongo/1/4/mongos.log
# Where and how to store data.
#storage:
#!!!
# dbPath: /opt/mongo/1/4
# journal:
# enabled: true
# engine:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
#!!!
pidFilePath: /opt/mongo/1/4/mongos.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
#!!!
port: 9014
#!!!
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
#security:
#operationProfiling:
#replication:
#!!!
sharding:
#!!!
configDB: C/192.168.10.101:9024
## Enterprise-Only Options
#auditLog:
#snmp:
将操作流程命令给出如下:
1、规划
1:1、5、6、os
2:1、2、6、c
3:1、2、3、c
4:2、3、4、c
5:3、4、5
6:4、5、6
2、创建配置文件和目录
3、启动mongod
mongod -f 11.conf
mongod -f 12.conf
mongod -f 13.conf
mongod -f 21.conf
mongod -f 22.conf
mongod -f 23.conf
mongod -f 24.conf
mongod -f 31.conf
mongod -f 32.conf
mongod -f 33.conf
mongod -f 34.conf
mongod -f 41.conf
mongod -f 42.conf
mongod -f 43.conf
mongod -f 44.conf
mongod -f 51.conf
mongod -f 52.conf
mongod -f 53.conf
mongod -f 61.conf
mongod -f 62.conf
mongod -f 63.conf
4、分组
mongo --port 9011
cfg={
_id:"S1", members:[{
_id:0,host:'192.168.43.101:9011'}, {
_id:1,host:'192.168.43.101:9021'}, {
_id:2,host:'192.168.43.101:9031'}]};
rs.initiate(cfg)
mongo --port 9022
cfg={
_id:"S2", members:[{
_id:0,host:'192.168.43.101:9022'}, {
_id:1,host:'192.168.43.101:9032'}, {
_id:2,host:'192.168.43.101:9041'}]};
rs.initiate(cfg)
mongo --port 9033
cfg={
_id:"S3", members:[{
_id:0,host:'192.168.43.101:9033'}, {
_id:1,host:'192.168.43.101:9042'}, {
_id:2,host:'192.168.43.101:9051'}]};
rs.initiate(cfg)
mongo --port 9043
cfg={
_id:"S4", members:[{
_id:0,host:'192.168.43.101:9043'}, {
_id:1,host:'192.168.43.101:9052'}, {
_id:2,host:'192.168.43.101:9061'}]};
rs.initiate(cfg)
mongo --port 9053
cfg={
_id:"S5", members:[{
_id:0,host:'192.168.43.101:9053'}, {
_id:1,host:'192.168.43.101:9062'}, {
_id:2,host:'192.168.43.101:9012'}]};
rs.initiate(cfg)
mongo --port 9063
cfg={
_id:"S6", members:[{
_id:0,host:'192.168.43.101:9063'}, {
_id:1,host:'192.168.43.101:9013'}, {
_id:2,host:'192.168.43.101:9023'}]};
rs.initiate(cfg)
mongo --port 9024
cfg={
_id:"C", members:[{
_id:0,host:'192.168.43.101:9024'}, {
_id:1,host:'192.168.43.101:9034'}, {
_id:2,host:'192.168.43.101:9044'}]};
rs.initiate(cfg)
5、启动并连接mongos
mongos -f os.conf
mongo --port 9014
6、增加分片
sh.addShard("S1/192.168.43.101:9011")
sh.addShard("S2/192.168.43.101:9022")
sh.addShard("S3/192.168.43.101:9033")
sh.addShard("S4/192.168.43.101:9043")
sh.addShard("S5/192.168.43.101:9053")
sh.addShard("S6/192.168.43.101:9063")
7、启动数据分片功能
use admin
db.runCommand({
enableSharding:"stumis"})
db.runCommand({
shardCollection:"stumis.students",key:{
"_id":"hashed"}})
8、批量插入数据
use stumis
for(var i=1; i<=100; i++) {
db.students.insert( {
name:"S"+i,age:i});}
9、查看分片效果
sh.status()
文章浏览阅读1k次。通过使用ajax方法跨域请求是浏览器所不允许的,浏览器出于安全考虑是禁止的。警告信息如下:不过jQuery对跨域问题也有解决方案,使用jsonp的方式解决,方法如下:$.ajax({ async:false, url: 'http://www.mysite.com/demo.do', // 跨域URL ty..._nginx不停的xhr
文章浏览阅读2k次。关于在 Oracle 中配置 extproc 以访问 ST_Geometry,也就是我们所说的 使用空间SQL 的方法,官方文档链接如下。http://desktop.arcgis.com/zh-cn/arcmap/latest/manage-data/gdbs-in-oracle/configure-oracle-extproc.htm其实简单总结一下,主要就分为以下几个步骤。..._extproc
文章浏览阅读1.5w次。linux下没有上面的两个函数,需要使用函数 mbstowcs和wcstombsmbstowcs将多字节编码转换为宽字节编码wcstombs将宽字节编码转换为多字节编码这两个函数,转换过程中受到系统编码类型的影响,需要通过设置来设定转换前和转换后的编码类型。通过函数setlocale进行系统编码的设置。linux下输入命名locale -a查看系统支持的编码_linux c++ gbk->utf8
文章浏览阅读750次。今天准备从生产库向测试库进行数据导入,结果在imp导入的时候遇到“ IMP-00009:导出文件异常结束” 错误,google一下,发现可能有如下原因导致imp的数据太大,没有写buffer和commit两个数据库字符集不同从低版本exp的dmp文件,向高版本imp导出的dmp文件出错传输dmp文件时,文件损坏解决办法:imp时指定..._imp-00009导出文件异常结束
文章浏览阅读143次。当下是一个大数据的时代,各个行业都离不开数据的支持。因此,网络爬虫就应运而生。网络爬虫当下最为火热的是Python,Python开发爬虫相对简单,而且功能库相当完善,力压众多开发语言。本次教程我们爬取前程无忧的招聘信息来分析Python程序员需要掌握那些编程技术。首先在谷歌浏览器打开前程无忧的首页,按F12打开浏览器的开发者工具。浏览器开发者工具是用于捕捉网站的请求信息,通过分析请求信息可以了解请..._初级python程序员能力要求
文章浏览阅读7.6k次,点赞2次,收藏6次。@Service标注的bean,类名:ABDemoService查看源码后发现,原来是经过一个特殊处理:当类的名字是以两个或以上的大写字母开头的话,bean的名字会与类名保持一致public class AnnotationBeanNameGenerator implements BeanNameGenerator { private static final String C..._@service beanname
文章浏览阅读6.9w次,点赞73次,收藏463次。1.前序创建#include<stdio.h>#include<string.h>#include<stdlib.h>#include<malloc.h>#include<iostream>#include<stack>#include<queue>using namespace std;typed_二叉树的建立
文章浏览阅读7.1k次。在Asp.net上使用Excel导出功能,如果文件名出现中文,便会以乱码视之。 解决方法: fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);_asp.net utf8 导出中文字符乱码
文章浏览阅读2.1k次,点赞4次,收藏23次。第一次实验 词法分析实验报告设计思想词法分析的主要任务是根据文法的词汇表以及对应约定的编码进行一定的识别,找出文件中所有的合法的单词,并给出一定的信息作为最后的结果,用于后续语法分析程序的使用;本实验针对 PL/0 语言 的文法、词汇表编写一个词法分析程序,对于每个单词根据词汇表输出: (单词种类, 单词的值) 二元对。词汇表:种别编码单词符号助记符0beginb..._对pl/0作以下修改扩充。增加单词
文章浏览阅读773次。我在使用adb.exe时遇到了麻烦.我想使用与bash相同的adb.exe shell提示符,所以我决定更改默认的bash二进制文件(当然二进制文件是交叉编译的,一切都很完美)更改bash二进制文件遵循以下顺序> adb remount> adb push bash / system / bin /> adb shell> cd / system / bin> chm..._adb shell mv 权限
文章浏览阅读6.8k次,点赞12次,收藏125次。1. 单目相机标定引言相机标定已经研究多年,标定的算法可以分为基于摄影测量的标定和自标定。其中,应用最为广泛的还是张正友标定法。这是一种简单灵活、高鲁棒性、低成本的相机标定算法。仅需要一台相机和一块平面标定板构建相机标定系统,在标定过程中,相机拍摄多个角度下(至少两个角度,推荐10~20个角度)的标定板图像(相机和标定板都可以移动),即可对相机的内外参数进行标定。下面介绍张氏标定法(以下也这么称呼)的原理。原理相机模型和单应矩阵相机标定,就是对相机的内外参数进行计算的过程,从而得到物体到图像的投影_相机-投影仪标定
文章浏览阅读2.2k次。文章目录Wayland 架构Wayland 渲染Wayland的 硬件支持简 述: 翻译一篇关于和 wayland 有关的技术文章, 其英文标题为Wayland Architecture .Wayland 架构若是想要更好的理解 Wayland 架构及其与 X (X11 or X Window System) 结构;一种很好的方法是将事件从输入设备就开始跟踪, 查看期间所有的屏幕上出现的变化。这就是我们现在对 X 的理解。 内核是从一个输入设备中获取一个事件,并通过 evdev 输入_wayland