zoukankan      html  css  js  c++  java
  • mongoDB-3.x Master Slave Replication

    mongoDB-3.x Master Slave Replication

    官方文档:

    注意:虽然,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


    可以有多台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
    mongoDB-3.x <wbr>Master <wbr>Slave <wbr>Replication

    调试信息一览
    
    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"} );
    mongoDB-3.x <wbr>Master <wbr>Slave <wbr>Replication

    更新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})
    mongoDB-3.x <wbr>Master <wbr>Slave <wbr>Replication

    mongoDB-3.x <wbr>Master <wbr>Slave <wbr>Replication

    mongoDB-3.x <wbr>Master <wbr>Slave <wbr>Replication

    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
    mongoDB-3.x <wbr>Master <wbr>Slave <wbr>Replication


  • 相关阅读:
    HTTP响应状态码整理
    Python通用爬虫,聚焦爬虫概念理解
    HTTP无状态协议理解
    会话与事务知识点总结
    并发一致性知识点整理
    使用隔离级别read committed隐式解决并发冲突
    多并发笔记整理
    git基本使用
    Docker其他
    Docker Bind Mount 与 Volume
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814255.html
Copyright © 2011-2022 走看看