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. static 使用,静态变量

    由static修饰,属于整个类,被类对象共享, 可以由类名,对象名访问 static可以修饰变量,方法,代码块 public class HelloWorld { static String clas ...

  2. [转载] Android Studio 上第一个 Xposed 模块

    本文转载自: http://www.open-open.com/lib/view/open1451364108964.html 环境: 已root手机一枚 Android Studio一枚 官方文档参 ...

  3. 解决C# 转到定义时打开的是元数据文件而非源代码文件的问题

    原因:添加引用时 使用的是“浏览"选项卡,选择了项目生成的dll作为引用的内容. 解决:添加引用时 使用的是"项目"选项卡,选择了项目本身作为引用的内容.

  4. python-操作MySQL数据库

    1.安装MySQLdb? 为了用DB-API编写MySQL脚本,必须确保已经安装了MySQL.复制以下代码,并执行: #!/usr/bin/python # -*- coding: UTF-8 -*- ...

  5. [原创]PCB知识补充

    近期又要使用Altium进行PCB板的绘制,算起来从大学课上第一次接触Protel99SE到现在已经算是半个熟练工了.不过现在想来还是能回忆起第一次使用的情景,对着一幅简单的原理图使用着自动连线的功能 ...

  6. Bootstrap 栅格系统(转载)

    源地址:http://www.cnblogs.com/linjiqin/p/3559800.html Bootstrap 栅格系统 目录1.简介2.栅格选项3.列偏移4.嵌套列5.列排序 1.简介Bo ...

  7. oracle中,拼接的字符串给游标赋值

    直接open cur from sql;即可. 例子: create or replace procedure test(tableName varchar2) is TYPE cur_type IS ...

  8. PHP安装rrdtool扩展

    首先,我的环境是Centos 6.5 PHP版本是5.51.首先安装rrdtool需要的依赖库文件   yum -y install pango* 2.先服务器安装rrdtool  wget http ...

  9. subprocess添加超时功能

    def TIMEOUT_COMMAND(command, timeout): """call shell-command and either return its ou ...

  10. [转] mhvtl虚拟磁带库的安装与应用

    转自:candon123  -- http://candon123.blog.51cto.com/704299/388192/ 1.获取mhvtl: 官方网站:http://mhvtl.nimsa.u ...