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. python第十一天-----补:线程池

    低版本: #!/usr/bin/env python import threading import time import queue class TreadPool: ""&q ...

  2. 修改myeclipse的servlet模板

    今天修改myeclipse的servlet模板时,发生 Could not create the view: An unexpected exception was thrown.错误. 解决方案:1 ...

  3. Oracle 10g -- 修改DB的编码

    修改DB的原因是:因为我的DB不支持中文,所以每当我向数据库表中插入一条数据的时候,中文就都变了类似于“?(是反问号)”的乱码,为了能顺利插入成功,故做了此次修改; 系统:windows XP 英文版 ...

  4. ln 软链接与硬链接的区别再次回顾

    以下是整理的笔记 软硬链接区别 硬链接 软链接 文件有相同的 inode 及 data block 是另一个文件 只能对已存在的文件进行创建 可以对不存在的文件进行创建 不能交叉文件系统进行硬链接的创 ...

  5. sqlserver,mysql,oracle通用的模拟和改进的全文搜索算法

    问:数据库效率最低的地方是什么? 答:表扫描 问:表扫描常见的情况是 答:like '%a%' 这类查询 如果使用全文检索引擎,又无法满足我们的需求的时候怎么办,比如要从 一个商品名称 "农 ...

  6. XE3随笔5:Format与转义字符

    unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...

  7. hdoj 1874 畅通工程续

    Problem Description 某省自从实行了很多年的畅通工程计划后,终于修建了很多路.不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行 ...

  8. Myeclipse/eclipse的Web project改写成Maven项目

    1.导入或建立web项目时加上maven的设置 2.加入如下代码:<dependencies>标签下加入红色部分 <dependencies> <dependency&g ...

  9. 配置org.springframework.scheduling.quartz.CronTriggerBean(转)

    注意:定时器方法里如果执行动作的时间超出了定时器的周期,将会产生两个方法同时执行的情况. 一个Quartz的CronTrigger表达式分为七项子表达式,其中每一项以空格隔开,从左到右分别是:秒,分, ...

  10. web浏览器工作原理

    HTML在浏览器里的渲染原理 我们打开的页面(Web页面)在各种不同的浏览器中运行,浏览器载入.渲染页面的速度直接影响着用户体验,简单地说下页面渲染,页面渲染就是浏览器将html代码根据CSS定义的规 ...