mongo(五)副本集

配置文件

1-3为三个存储节点,其实一个为Primary,两个secondary作为备份,4为仲裁节点
# mongod.conf

#where to log
logpath=/home/data/db/mongodb2.log logappend=true # fork and run in background
fork=true port=33197 dbpath=/home/yuxianda/data/db/db2 # location of pidfile
pidfilepath=/home/yuxianda/data/db/mongod2.pid # Listen to local interface only. Comment out to listen on all interfaces.
bind_ip=127.0.0.1 #datebase in diffrent file
directoryperdb=true # fsync time
#syncdelay=5 # Disables write-ahead journaling
# nojournal=true # Enables periodic logging of CPU utilization and I/O wait
#cpu=true # Turn on/off security. Off is currently the default
#noauth=true
#auth=true # Verbose logging output.
#verbose=true # Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck=true # Enable db quota management
#quota=true # Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#diaglog=0 # Ignore query hints
#nohints=true # Enable the HTTP interface (Defaults to port 28017).
#httpinterface=true # Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting=true # Turns off table scans. Any query that would do a table scan fails.
#notablescan=true # Disable data file preallocation.
#noprealloc=true # Specify .ns file size for new databases.
# nssize=<size> # Replication Options # in replicated mongo databases, specify the replica set name here
replSet=android-test
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile

mongo.conf

执行配置

mongod -f conf.conf
 

设定副本集合:

mongo --port 33198
use admin
db.runCommand({"replSetInitiate":{
"_id":"android-test",
"members":[
{
"_id":1,
"host":"127.0.0.1:33198"
},
{
"_id":2,
"host":"127.0.0.1:33197"
},
{
"_id":3,
"host":"127.0.0.1:33196"
}
]}})

增加仲裁节点

rs.addArb("127.0.0.1:33195")
 
#!/usr/bin/env python
#-*- encoding:utf-8 -*- from pymongo import MongoClient, MongoReplicaSetClient dbList = '127.0.0.1:33198,127.0.0.1:33197,127.0.0.1:33196' def init(dbname):
try:
client = MongoReplicaSetClient(dbList, replicaSet='android- test')
db = client[dbname]
return db
except Exception as e:
print 'error:%s'%e
return False if __name__ == '__main__':
db = init('test')
print db.appinfo.find_one()
 

mongo(五)副本集的更多相关文章

  1. mongodb 系列 ~ mongo的副本集(2)

    一 简介:来试试更改副本集的oplog问题二 背景: oplog的作用类似于mysql的binlog,传递增量操作到从节点 三 oplog介绍   1 oplog在local库:      1 mas ...

  2. mongodb 系列 ~ mongo的副本集(3)

    一 简介:今天咱们来聊聊mongodb复制的具体一些案例 二 副本集 1 当mongodb采用全量复制时,如何观察全量复制的进度 对比文件本身和primary大小 2 mongodb全量复制的过程 旧 ...

  3. mongo转换副本集

    本文介绍如何把独立的mongo实例转换成包含3个成员的副本集.开发和测试使用独立实例,生产使用副本集.如何安装独立的mongo实例本文不再赘述. 如果在部署副本集时还没有安装mongo实例,可以查看部 ...

  4. Mongo分片+副本集集群搭建

    一. 概念简单描述 1. MongoDB分片集群包含组件: mongos,configserver,shardding分片 2. Mongos:路由服务是Sharded cluster的访问入口,本身 ...

  5. mongo学习- 副本集 大多数原则

    副本集中有一个重要的概念“大多数”,意思是说,选择主节点需要大多数决定(本人亲自做了实验) 步骤: 1.开启副本集(如果没有配置好 副本集的 亲参考我的上篇文章  https://www.cnblog ...

  6. mongo学习- 副本集配置(事故自动转移)

    一.安装mongodb 二.复制2份 三.启动 (1)mongod --config C:\mongofuben\zhu\conf\mongodb.config --replSet haibin/12 ...

  7. mongodb(副本集)

    副本集是mongo下的一种集群配置方式: 1.通过oplog的方式将主节点数据同步到副本节点,oplog不记录查询语句(因为不改变数据): 2.mongo的副本集可以有一个主节点,多个副本节点,主节点 ...

  8. MongoDB副本集的搭建

    副本集是mongodb提供的一种高可用解决方案.相对于原来的主从复制,副本集能自动感知primary节点的下线,并提升其中一个Secondary作为Primary. 整个过程对业务透明,同时也大大降低 ...

  9. mongodb副本集的从库永久性设置setSlaveOk

    今天在生产环境下面搭了一个mongo的副本集,但开发那边要求副本集读写分离. 坑爹的是每次上副本集的时候都要设置db.getMongo().setSlaveOk()才能访问数据.感觉很是苦逼. 后来开 ...

随机推荐

  1. noip2006 2^k进制数

    设r是个2k进制数,并满足以下条件: (1)r至少是个2位的2k进制数. (2)作为2k进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后,则q的总位数不超过w ...

  2. HDU 3065 病毒侵袭持续中(AC自动机)

    这题数据太水,一开始没有加上Get的方法也能AC..话说AC自动机中一定要注意加上Get的方法!(不然,同一个后缀的其他单词就没被算上了.) 代码如下: #include <stdio.h> ...

  3. webform组合查询和分页

    1.组合查询(1)数据访问类 //参数1:SQL语句 参数2:哈希表public List<Users> chas(string s,Hashtable has) { List<Us ...

  4. 转 苹果的新编程语言 Swift 简介

    苹果官方文档地址 https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Pro ...

  5. BigDecimal最基础用法

    BigDecimal最基础用法 用字符串生成的BigDecimal是不会丢精度的. 简单除法. public class DemoBigDecimal { public static void mai ...

  6. hibernate执行session.createQuery(hql)时hql若有参数则报错

    项目从Jboss换位Tomcat服务器,打开如下Hql都报错: SELECT COUNT(*) FROM SystemUser WHERE STATUS != -1 解决方法:在Lib中加入antlr ...

  7. ubuntu 16.04软件源

    来源:模板:16.04source   deb http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted universe multive ...

  8. Linux crontab命令的使用方法

    crontab命令常见于Unix和Linux的操作系统之中,用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于"crontab"文件中,以供之后读取和执行. 在 ...

  9. Web大规模高并发请求和抢购的解决方案

    电商的秒杀和抢购,对我们来说,都不是一个陌生的东西.然而,从技术的角度来说,这对于Web系统是一个巨大的考验.当一个Web系统,在一秒钟内收到数以万计甚至更多请求时,系统的优化和稳定至关重要.这次我们 ...

  10. Python学习笔记异常

    在程序代码中,可能会有各种错误的情况出现,且产生错误的结果是后面的代码都无法执行,即使是一点无关紧要的错误,如图: 在这样的情况下,我们需要异常处理,对程序代码中的错误抛出异常信息,且不影响后面的代码 ...