在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的主,从,仲裁节点搭建的更多相关文章

  1. mongodb副本集仲裁节点搭建

    服务器准备: 主节点192.168.100.106 从节点192.168.100.107 仲裁节点192.168.100.108 三台服务器: 关闭防火墙 service iptables stop ...

  2. docker-compose搭建mongoDB副本集(1主+1副+1仲裁)

    一.基本概念 1.副本集:一个副本集就是一组MongoDB实例组成的集群,由一个主(Primary)服务器和多个备份(Secondary)服务器构成 2.主节点(master):主节点接收所有写入操作 ...

  3. Mongodb主、副、仲裁节点集群安装

    mongodb 的集群方式主要分为三种Replica Set / Sharding / Master-Slaver ,这里只说明最简单的集群搭建方式(生产环境),如果有多个节点可以此类推或者查看官方文 ...

  4. mongodb主从(副本集附仲裁节点)部署带认证模式

    环境:OS:CentOS 7DB:3.0.15机器角色:192.168.1.134:10001 主192.168.1.135:10002 从192.168.1.135:10003 仲裁节点 1.下载相 ...

  5. MongoDB副本集(一主一备+仲裁)环境部署-运维操作记录

    MongoDB复制集是一个带有故障转移的主从集群.是从现有的主从模式演变而来,增加了自动故障转移和节点成员自动恢复.MongoDB复制集模式中没有固定的主结点,在启动后,多个服务节点间将自动选举产生一 ...

  6. MongoDB 3.0 常见集群的搭建(主从复制,副本集,分片....)

      一.mongodb主从复制配置 主从复制是mongodb最常用的复制方式,也是一个简单的数据库同步备份的集群技术,这种方式很灵活.可用于备份,故障恢复,读扩展等. 最基本的设置方式就是建立一个主节 ...

  7. CentOS7 安装MongoDB 3.0服务器

    1,下载&安装 MongoDB 3.0 正式版本发布!这标志着 MongoDB 数据库进入了一个全新的发展阶段,提供强大.灵活而且易于管理的数据库管理系统.MongoDB宣称,3.0新版本不只 ...

  8. 新年新技术:MongoDB 3.0

    前一篇介绍了HTTP/2,这一篇简单介绍下3月3号发布的MongoDB 3.0. What’s new in MongoDB 3.0? 新的存储引擎WiredTiger MongoDB 3.0的存储引 ...

  9. MongoDB 3.0(1):CentOS7 安装MongoDB 3.0服务

    目录(?)[-] 1下载安装 2MongoDB CRUD 1创建数据 2更新数据 3删除 4查询 5更多方法 3MongoDB可视化工具 4总结   本文原文连接: http://blog.csdn. ...

随机推荐

  1. 5-1 源码包与RPM包的区别

    1.区别 <1>安装之前的区别:概念上的不同(是否开源等,更多请点我) <2>安装之后的区别:安装位置不同 2.RPM包安装位置 <1>是安装在默认位置中,但不是确 ...

  2. mysql5.6启动占用内存很大的解决方法

    vps的内存为512M,安装好nginx,php等启动起来,mysql死活启动不起来看了日志只看到对应pid被结束了,后跟踪看发现是内存不足被killed; 调整my.cnf 参数,重新配置(系统默认 ...

  3. Get access to Servlet

    import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class LoginServlet extend ...

  4. Scrum 项目2.0

    阅读教材第8章,8.1~8.3节 P157~168,了解获取用户需求的办法,每个组可以选择一二加以应用. 8.4节P168-171 查阅NABCDA模型的具体说明. 2.SCRUM 流程的步骤 1 完 ...

  5. (总结)Linux下使用rsync最快速删除海量文件的方法

    昨天遇到了要在Linux下删除海量文件的情况,需要删除数十万个文件.这个是之前的程序写的日志,增长很快,而且没什么用.这个时候,我们常用的删除命令rm -fr * 就不好用了,因为要等待的时间太长.所 ...

  6. A quest for the full InnoDB status

    When running InnoDB you are able to dig into the engine internals, look at various gauges and counte ...

  7. SQL : 在SQL Server 2008(Or Express)中如何Open并编辑数据表【转】

    来源:http://www.cnblogs.com/wsdj-ITtech/archive/2011/04/28/2031601.html 通常在SQL Server 2005中,我们可以通过SQL ...

  8. Knockout.js, Asp.Net MVC and Bootstrap 前端设计

    原文地址:http://ddmvc4.codeplex.com/ 原文名称:Design and Develop a website using ASP.NET MVC 4, EF, Knockout ...

  9. ASP.NET MVC 出现错误 “The view 'XXX' or its master was not found or no view engine support”

    来自:http://www.dengyukeji.com/archiver/tid-151.html 错误如下:The view 'XXX' or its master was not found o ...

  10. samba配置只读共享

    编辑smb.conf 1.在[global]中 找到 security = 将其改为 security = share 2. 在文件中加入自定义的共享目录 [attachment] path=/dat ...