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学习记录(二十二)——模式字符串与占位符
一.Java代码案例 @Test public void test10(){ int planet=7; String event="a disturban ...
- (转) An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms Table of contents: Gradient descent variants ...
- 在CentOS里使用MySQL Connector/C++
操作系统版本:CentOS6 64位 1,安装boost库.因为MySQL Connector/C++使用了boost库,所以必须先安装boost库,我们才能使用MySQL Connector/C++ ...
- dotnetConf
https://channel9.msdn.com/Events/dotnetConf/2016 https://channel9.msdn.com/Events/dotnetConf/2016?so ...
- MicroSoft Visual C++ 6.0怎么建立C++文件工程?
1.打开VC6.02.选择菜单中的"文件"->"新建",弹出"新建"对话框3.在"新建"对话框中选择四个Sheet ...
- Using CSV-Format Log Output
Including csvlog in the log_destination list provides a convenient way to import log files into a da ...
- Zend 安装 OpenExplorer插件
转自:http://blog.csdn.net/binyao02123202/article/details/8954249 OpenExplorer是一款打开导进来的项目文件或文件夹所在磁盘的位置的 ...
- unity, sceneview 中拾取球体gizmos
http://answers.unity3d.com/questions/745560/handle-for-clickable-scene-objects.html http://www.jians ...
- struts2异常处理及类型转换
一.struts2对异常的处理 1.自定义局部异常: <action> <exception-mapping result="sonException" exce ...
- python3倒叙字符串
google测试工程师的一道题: 设计一个函数,使用任意语言,完成以下功能: 一个句子,将句子中的单词全部倒排过来,但单词的字母顺序不变.比如,This is a real world,输出结果为 w ...