mongoDB-3.x Master Slave Replication
官方文档:
https://docs.mongodb.org/manual/core/master-slave/
https://docs.mongodb.org/manual/reference/program/mongod/#cli-mongod-master-slave
https://docs.mongodb.org/manual/reference/local-database/#local.sources
注意:虽然,3.x仍然支持master-slave模式,但因为不能自动Failover等相关限制,官方推荐使用Repica Set模式

IMPORTANT

Replica sets replace master-slave replication for most use cases. If possible, use replica sets rather than master-slave replication for all new production deployments. This documentation remains to support legacy deployments and for archival purposes only.

环境:
CentOS6.5 x64
mongoDB-3.2.0

安装请参看mongoDB-3.x安装配置(单机版)
可以有多台slave
Master: 192.168.192.10
mongod --master --port 27010 --fork --httpinterface --rest --jsonp --setParameter enableLocalhostAuthBypass=0 --pidfilepath /opt/mongodb/mongod-ms.pid --dbpath /opt/mongodb/db-ms --logpath /opt/mongodb/log/mongod-ms.log  --logappend --logRotate rename --timeStampFormat ctime
调试信息一览
rs.printReplicationInfo()

Slave: 192.168.192.11
mongod --slave --source 192.168.192.10:27010 --port 27010 --fork --httpinterface --rest --jsonp --setParameter enableLocalhostAuthBypass=0 --pidfilepath /opt/mongodb/mongod-ms.pid --dbpath /opt/mongodb/db-ms --logpath /opt/mongodb/log/mongod-ms.log  --logappend --logRotate rename --timeStampFormat ctime
注意:--source参数只需要在第一次启动时加上,之后重启只需要--slave参数
在不指定--source的参数的情况下,在mongo shell下手动指定master
use local
db.sources.find()
db.sources.insert( { host: "192.168.192.10:27010"} );

更新master
db.sources.update( { host : "192.168.192.10:27010" },
                   { $set : { host : "192.168.192.10:27018" } } )

rs.printSlaveReplicationInfo()

测试一:master宕机
master mongo shell执行
db.adminCommand({shutdown : 1, force : true})

master宕机后,仍然可以查询,但不能写入

测试二.Failing over to a Slave

To permanently failover from a unavailable or damaged master (A in the following example) to a slave (B):

  1. Shut down A.

  2. Stop mongod on B.

  3. Back up and move all data files that begin with local on B from the dbPath.

    WARNING

    Removing local.* is irrevocable and cannot be undone. Perform this step with extreme caution.

  4. Restart mongod on B with the --master option.

NOTE

This is a one time operation, and is not reversible. A cannot become a slave of B until it completes a full resync.

mongod --shutdown --dbpath /opt/mongodb/db-ms/
mongod --master  --port 27010 --fork --httpinterface --rest --jsonp --setParameter enableLocalhostAuthBypass=0 --pidfilepath /opt/mongodb/mongod-ms.pid --dbpath /opt/mongodb/db-ms --logpath /opt/mongodb/log/mongod-ms.log  --logappend --logRotate rename --timeStampFormat ctime

转载于:https://www.cnblogs.com/lixuebin/p/10814255.html

mongoDB-3.x Master Slave Replication相关推荐

  1. MongoDB学习笔记——Master/Slave主从复制

    Master/Slave主从复制 主从复制MongoDB中比较常用的一种方式,如果要实现主从复制至少应该有两个MongoDB实例,一个作为主节点负责客户端请求,另一个作为从节点负责从主节点映射数据,提 ...

  2. Master/Slave知识

    1.master上授权给slave mysql>grant all on *.* to repadmin@'218.6.67.75' identified by 'backup'; mysql& ...

  3. 搭建主从数据库出现的错误 error connecting to master ‘slave@172.17.0.2:3306‘ - retry-time: 30 retries: 1

    在搭建主从数据库的时候出现了报错 出现错误的截图: 解决办法: 重新授权 CREATE USER 'slave'@'%' IDENTIFIED BY '123456'; GRANT REPLICATI ...

  4. mysql配置master_mysql 主从配置(master/slave)

    1.  在每台服务器上创建复制账号(也可以只在master上创建用户,这里配置两个是为了方便以后切换) 备库运行的I/O县城需要建立一个到主库的TCP/IP连接,所以必须在主库创建一个用户,并赋予合适 ...

  5. Mysql的master,slave的配置

    MYSQL的master,slave环境的搭建<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:off ...

  6. 适合MySQL master/slave模式的JDBC driver: lbpool

    去年写了篇MySQL分表实现上百万上千万记录分布存储的批量查询设计模式的文章,思路是基于MySQL手动分表的.缺点是增加了程序的复杂性.现在有一个更简单和方便的现成的产品了,那就是lbpool lbp ...

  7. Redis(八):Redis的复制(Master/Slave)

    Redis的复制(Master/Slave)目录导航: 是什么 能干嘛 怎么玩 复制原理 哨兵模式(sentinel) 复制的缺点 是什么 官网 行话:也就是我们所说的主从复制,主机数据更新后根据配置 ...

  8. redis主从复制_Redis 的主从复制(Master/Slave)

    1. 是什么 行话:也就是我们所说的主从复制,主机数据更新后根据配置和策略自动同步到备机的 master/slave 机制,Master以写为主,Slave 以读为主 2. 能干嘛 数据冗余:主从复制 ...

  9. master slave mysql_MYSQL高可用之复制(MASTER/SLAVE)

    MYSQL高可用之复制(MASTER/SLAVE) 随着互联网的快速发展,对数据库的访问已经越来越频繁,仅凭单个服务器已经无法应对高并发的访问,也无法满足数据库提供7*24的服务,这个时候我们就必须考 ...

最新文章

  1. 程序员的岗位方向和所需技能都有哪些?
  2. python面向对象开发(类的属性-精讲
  3. 8000 字 + 21 张图,服务端高并发分布式架构 14 次演进之路
  4. 微软宣布新命令行工具 Windows Terminal 和 WSL2
  5. C++创建动态链接库(*.dll)
  6. RunLoop已入门?不来应用一下?
  7. EasyUI:datagrid冻结表头
  8. Qcon2017实录|Service Mesh:下一代微服务
  9. MySQL 入门常用命令大全
  10. 豆瓣电影推荐系统(Ⅰ)ItemCF算法原理
  11. 拟合美国人口matlab编码,美国人口数据的阻滞增长模型拟合分析
  12. 实验设计与分析 (总结8)
  13. donet编译原理(C#)
  14. 消费品企业,会员营销四大痛点
  15. (一)关于爬虫之请求
  16. 电子元器件3D模型免费下载资源
  17. springboot2.0启动报错The APR based Apache Tomcat Native library which allows optimal performance in ...
  18. BZOJ 3786: 星系探索 ETT
  19. Ubuntu18.04下 LOAM_Velodyne 的编译安装(PCL为1.8.1)
  20. 汽车整车行业PLM解决方案

热门文章

  1. 计算机中的显示器连线时总线吗,科普:选择电脑显示器连接线技巧,这5种接口要熟知...
  2. 台湾“国安局”网站现猫头鹰网页 网友:丑到以为被黑
  3. 下载excel模板为空记录
  4. OWASP top 10漏洞原理及防御(2017版官方)
  5. Excel获取当前文件所在目录
  6. upload 附件上传流程(限制附件大小格式)
  7. 这些Web API真的有用吗? 别问,问就是有用
  8. 华为OD机试(2023A+B)考点分类
  9. 大连理工大学校长助理李俊杰教授来校调研
  10. 在互联网行业如何高效快速接单子