MongoDB 3.0.6的主,从,仲裁节点搭建
在MongoDB所在路径创建log和data目录
mkdir log
mkdir data
在data目录下 创建master、slaver、arbiter路径
mkdir master
mkdir slaver
mkdir arbiter
新建日志文件
在log下执行 touch mongodb.log 创建log文件
在MongoDB根目录下创建master.pid slaver.pid arbiter.conf.pid (用来记录启动的进程号)
daemon方式启动的fork参数也可以配置配置文件中 在bin下创建master.conf slaver.conf arbiter.conf文件:配置如下 (主,备,仲裁节点)
创建master.conf
#master.conf
dbpath=/usr/local/mongodb-linux-x86_64-3.0.6/data/master
logpath=/usr/local/mongodb-linux-x86_64-3.0.6/log/master.log
pidfilepath=/usr/local/mongodb-linux-x86_64-3.0.6/log/master.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=192.168.77.130
port=27017
oplogSize=10000
fork=true
noprealloc=true
创建
slaver.conf
dbpath=/usr/local/mongodb-linux-x86_64-3.0.6/data/slaver
logpath=/usr/local/mongodb-linux-x86_64-3.0.6/log/slaver.log
pidfilepath=/usr/local/mongodb-linux-x86_64-3.0.6/log/slaver.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=192.168.77.130
port=27018
oplogSize=10000
fork=true
noprealloc=true
创建
#arbiter.conf
dbpath=/usr/local/mongodb-linux-x86_64-3.0.6/data/arbiter
logpath=/usr/local/mongodb-linux-x86_64-3.0.6/log/arbiter.log
pidfilepath=/usr/local/mongodb-linux-x86_64-3.0.6/arbiter.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=192.168.77.130
port=27019
oplogSize=10000
fork=true
noprealloc=true
主从节点启动
./mongod -f master.conf
./mongod -f slaver.conf
./mongod -f arbiter.conf
连接相应节点
./mongo 10.1.235.62:27017
./mongo 10.1.235.61:27018
......
参数含义:
dbpath:数据存放的目录
logpath:日志存放路径
pidfilepath:用于记录进程号的文件
logappend: 记录日志
relSet:replica set的名字
bind_ip:mongodb的ip地址
port:端口号
oplogSize:mongodb操作日志文件的最大大小
noprealloc:不预先分配存储
启动客户端连接
./mongodb
退出
在shell中输入exit
相关命令:
show dbs; show collections; show users; show profile; show logs
如果想创建一个数据库名称 <coc>
use mydb
要检查当前选择的数据库使用命令:
db
创建的数据库mydb 列表中是不存在的。要显示的数据库,需要把它插入至少一个文件。
db.movie.insert({"name":"tutorials yiibai"})
配置主、从、仲裁节点:
首先连接一个mongdb地址
./mongo 192.168.77.130:27017
执行初始化配置,这里的priority的值越高,初始化完后,该节点就会成为主节点,arbiterOnly:true 代表该节点为仲裁节点。
cfg={ _id:"testrs", members:[ {_id:0,host:"192.168.77.130:27017",priority:2}, {_id:1,host:"192.168.77.130:27018",priority:1},{_id:2,host:"192.168.77.130:27019",arbiterOnly:true}] };
执行初始化
rs.initiate(cfg)
通过rs.status()查看状态。 这里在自己的机子上初始化可能会报 这个该死的问题折磨死我了,最后发现是磁盘空间不足导致的。所以在自己的机子上做集群可能会无法初始化
具体还在想办法。。。反正原因大概是这个原因~
如果你不想用这种模式,毕竟有时候虚拟机磁盘会不够初始化,可以就搭个单节点自己玩,那么要删除master.conf文件中的replSet=testrs
然后重启
./mongod -f master.conf
随后连接自己~
./mongo 192.168.77.129:27017
OK了~自己玩吧~
停止mongodb时 千万不要Kill -9 否则会比较麻烦~ 用kill -15就可以啦~
MongoDB与传统SQL:
db.users.find() select * from users
db.users.find({"age" : 27}) select * from users where age = 27
db.users.find({"username" : "joe", "age" : 27}) select * from users where "username" = "joe" and age = 27
db.users.find({}, {"username" : 1, "email" : 1}) select username, email from users
db.users.find({}, {"username" : 1, "_id" : 0}) // no case // 即时加上了列筛选,_id也会返回;必须显式的阻止_id返回
db.users.find({"age" : {"$gte" : 18, "$lte" : 30}}) select * from users where age >=18 and age <= 30 // $lt(<) $lte(<=) $gt(>) $gte(>=)
db.users.find({"username" : {"$ne" : "joe"}}) select * from users where username <> "joe"
db.users.find({"ticket_no" : {"$in" : [725, 542, 390]}}) select * from users where ticket_no in (725, 542, 390)
db.users.find({"ticket_no" : {"$nin" : [725, 542, 390]}}) select * from users where ticket_no not in (725, 542, 390)
db.users.find({"$or" : [{"ticket_no" : 725}, {"winner" : true}]}) select * form users where ticket_no = 725 or winner = true
db.users.find({"id_num" : {"$mod" : [5, 1]}}) select * from users where (id_num mod 5) = 1
db.users.find({"$not": {"age" : 27}}) select * from users where not (age = 27)
db.users.find({"username" : {"$in" : [null], "$exists" : true}}) select * from users where username is null // 如果直接通过find({"username" : null})进行查询,那么连带"没有username"的纪录一并筛选出来
db.users.find({"name" : /joey?/i}) // 正则查询,value是符合PCRE的表达式
db.food.find({fruit : {$all : ["apple", "banana"]}}) // 对数组的查询, 字段fruit中,既包含"apple",又包含"banana"的纪录
db.food.find({"fruit.2" : "peach"}) // 对数组的查询, 字段fruit中,第3个(从0开始)元素是peach的纪录
db.food.find({"fruit" : {"$size" : 3}}) // 对数组的查询, 查询数组元素个数是3的记录,$size前面无法和其他的操作符复合使用
db.users.findOne(criteria, {"comments" : {"$slice" : 10}}) // 对数组的查询,只返回数组comments中的前十条,还可以{"$slice" : -10}, {"$slice" : [23, 10]}; 分别返回最后10条,和中间10条
db.people.find({"name.first" : "Joe", "name.last" : "Schmoe"}) // 嵌套查询
db.blog.find({"comments" : {"$elemMatch" : {"author" : "joe", "score" : {"$gte" : 5}}}}) // 嵌套查询,仅当嵌套的元素是数组时使用,
db.foo.find({"$where" : "this.x + this.y == 10"}) // 复杂的查询,$where当然是非常方便的,但效率低下。对于复杂查询,考虑的顺序应当是 正则 -> MapReduce -> $where
db.foo.find({"$where" : "function() { return this.x + this.y == 10; }"}) // $where可以支持javascript函数作为查询条件
db.foo.find().sort({"x" : 1}).limit(1).skip(10); // 返回第(10, 11]条,按"x"进行排序; 三个limit的顺序是任意的,应该尽量避免skip中使用large-number、
MongoDB 3.0.6的主,从,仲裁节点搭建的更多相关文章
- mongodb副本集仲裁节点搭建
服务器准备: 主节点192.168.100.106 从节点192.168.100.107 仲裁节点192.168.100.108 三台服务器: 关闭防火墙 service iptables stop ...
- docker-compose搭建mongoDB副本集(1主+1副+1仲裁)
一.基本概念 1.副本集:一个副本集就是一组MongoDB实例组成的集群,由一个主(Primary)服务器和多个备份(Secondary)服务器构成 2.主节点(master):主节点接收所有写入操作 ...
- Mongodb主、副、仲裁节点集群安装
mongodb 的集群方式主要分为三种Replica Set / Sharding / Master-Slaver ,这里只说明最简单的集群搭建方式(生产环境),如果有多个节点可以此类推或者查看官方文 ...
- mongodb主从(副本集附仲裁节点)部署带认证模式
环境:OS:CentOS 7DB:3.0.15机器角色:192.168.1.134:10001 主192.168.1.135:10002 从192.168.1.135:10003 仲裁节点 1.下载相 ...
- MongoDB副本集(一主一备+仲裁)环境部署-运维操作记录
MongoDB复制集是一个带有故障转移的主从集群.是从现有的主从模式演变而来,增加了自动故障转移和节点成员自动恢复.MongoDB复制集模式中没有固定的主结点,在启动后,多个服务节点间将自动选举产生一 ...
- MongoDB 3.0 常见集群的搭建(主从复制,副本集,分片....)
一.mongodb主从复制配置 主从复制是mongodb最常用的复制方式,也是一个简单的数据库同步备份的集群技术,这种方式很灵活.可用于备份,故障恢复,读扩展等. 最基本的设置方式就是建立一个主节 ...
- CentOS7 安装MongoDB 3.0服务器
1,下载&安装 MongoDB 3.0 正式版本发布!这标志着 MongoDB 数据库进入了一个全新的发展阶段,提供强大.灵活而且易于管理的数据库管理系统.MongoDB宣称,3.0新版本不只 ...
- 新年新技术:MongoDB 3.0
前一篇介绍了HTTP/2,这一篇简单介绍下3月3号发布的MongoDB 3.0. What’s new in MongoDB 3.0? 新的存储引擎WiredTiger MongoDB 3.0的存储引 ...
- MongoDB 3.0(1):CentOS7 安装MongoDB 3.0服务
目录(?)[-] 1下载安装 2MongoDB CRUD 1创建数据 2更新数据 3删除 4查询 5更多方法 3MongoDB可视化工具 4总结 本文原文连接: http://blog.csdn. ...
随机推荐
- JavaWeb学习记录(三)——网页中文编码问题
方法一: public void doGet(HttpServletRequest request, HttpServletResponse response) throws S ...
- Codeforces Round #137 (Div. 2)
A. Shooshuns and Sequence 显然\([k,n]\)之间所有数均要相同,为了求最少步数,即最多模拟\(n\)次操作即可. B. Cosmic Tables 映射\(x_i,y_i ...
- Java——网络编程
// TODO Auto-generated method stub //获取本地主机IP对象 InetAddress ip = InetAddress.getLocalHost(); Syst ...
- ps互补色
色彩中的互补色有红色与绿色互补,蓝色与橙色互补,紫色与黄色互补.在光学中指两种色光以适当的比例混合而能产生白光时,则这两种颜色就称为“互为补色”. 互补色是相对的混合的白色 互补色:在色环中某种颜色的 ...
- 解决方法:loadrunner 场景下执行webservice脚本是---报错10492 Error: Exception was raised when calling per-process-init function in extens
在vug下执行时,脚本无异常,但是在controller下执行时报下面错误,网上查了下,解决方法千奇百怪,但无一可行. 分析了下错误,似乎是初始化进程有关.想到rts中的设置习惯时以线程方式执行. 遂 ...
- python程序的调试方法
[转自:http://blog.csdn.net/luckeryin/article/details/4477233] 本文讨论在没有方便的IDE工具可用的情况下,使用pdb调试python程序 ...
- Android如何防止apk程序被反编译
作为Android应用开发者,不得不面对一个尴尬的局面,就是自己辛辛苦苦开发的应用可以被别人很轻易的就反编译出来. Google似乎也发现了这个问题,从SDK2.3开始我们可以看到在android-s ...
- OpenJudge计算概论-球弹跳高度的计算
/*======================================================================== 球弹跳高度的计算 总时间限制: 1000ms 内存 ...
- C#中的List<string>泛型类示例
在C#代码中使用一系列字符串(strings)并需要为其创建一个列表时,List<string>泛型类是一个用于存储一系列字 符串(strings)的极其优秀的解决办法.下面一起有一些Li ...
- Mac安装Appium
通过淘宝镜像安装 npm --registry http://registry.cnpmjs.org install -g appium 如果提示权限不够的话,需要加sudo,并输入对应密码 sudo ...