Master Server

  1. create mongo db folder with sub folders like data, conf, && log

    mkdir -p /opt/mongo/data
    mkdir -p /opt/mongo/conf
    mkdir -p /opt/mongo/log
  2. create a keyfile to secure mongo DB custer traffic. scp this file to slave server

    cd /srv/mongodb/
    openssl rand -base64 741 >>mongo-key
    chmod 700 mongo-key
  3. vi /opt/mongo/conf/master.conf

    dbpath=/opt/mongo/data
    logpath=/opt/mongo/log/mongodb.log
    logappend=true
    fork=true
    port=27017
    oplogSize=2048
  4. start mongo with command mongod --config /opt/mongo/conf/master.conf
  5. login mongo and create admin account && local account repl for the cluster

    > use admin
    > db.createUser({user:"root", pwd:"123456", roles:[{role:"root", db:"admin"}]})
    > db.createUser({user:"repl", pwd:"123456", roles:[{role:"dbOwner", db:"local"}]})
    > show users
    {
        "_id" : "admin.root",
        "user" : "root",
        "db" : "admin",
        "roles" : [
            {
                "role" : "root",
                "db" : "admin"
            }
        ]
    }
    {
        "_id" : "admin.repl",
        "user" : "repl",
        "db" : "admin",
        "roles" : [
            {
                "role" : "dbOwner",
                "db" : "local"
            }
        ]
    }
  6. modify the conf file and add the last 3 lines into the file

    dbpath=/opt/mongo/data
    logpath=/opt/mongo/log/mongodb.log
    logappend=true
    fork=true
    port=27017
    oplogSize=2048
     
     
    master=true
    auth=true
    keyFile=/opt/mongo/mongo-key
  7. restart mongo with new config file

    mongod --config /opt/mongo/conf/master.conf --shutdown
    mongod --config /opt/mongo/conf/master.conf

Slave Server

  1. create mongo db folder with sub folders like data, conf, && log; same as master
  2. copy the keyfile to mongo folder and modify the slave.conf

    dbpath=/opt/mongo/data
    logpath=/opt/mongo/log/mongodb.log
    logappend=true
    fork=true
    port=27017
    oplogSize=2048
     
     
    slave=true
    auth=true
    keyFile=/opt/mongo/mongo-key
    source = [master ip]:[port]
  3. start slave server

    mongod --config /opt/mongo/conf/slave.conf
  4. login slave with admin credential, and active slave (important)

    rs.slaveOk()

Test

Create a test db and insert values into a new collection on master node

> use test
switched to db test
> db.products.insert( { item: "card", qty: 15 } )
WriteResult({ "nInserted" : 1 })
> show collections
products

Login to slave node and then verfiy if the new added test db exisits.

After the verification done, remember to delete the test db with command

> use test
switched to db test
> db.dropDatabase()
"dropped" "test""ok" : 1 }

 

MongoDB Master-Slave cluster with authentication setup的更多相关文章

  1. mongodb - Master Slave Replication

    master-slave复制模式大多场景下都被replicat sets代替.官方也建议使用replicat sets. master-slave复制不支持自动failover. master-sla ...

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

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

  3. Redis master/slave,sentinel,Cluster简单总结

    现在互联网项目中大量使用了redis,本文著主要分析下redis 单点,master/slave,sentinel模式.cluster的一些特点. 一.单节点模式 单节点实例还是比较简单的,平时做个测 ...

  4. Mongodb集群——master/slave

    集群的配置 (本测试放于同一台机器进行配置,所以IP地址一样,如果是在不同的服务器上更换IP便可以)   1.目录结构       拷贝两份mongodb到/home/scotte.ye/mongo1 ...

  5. 转】MongoDB主从复制实验 master/slave

    原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/4/ 感谢! Posted: May 31, 2013 Ta ...

  6. 【摘录】JDBC Master Slave(JDBC方式的JMS集群)

    JDBC Master Slave First supported in ActiveMQ version 4.1 If you are using pure JDBC and not using t ...

  7. redis 学习笔记(3)-master/slave(主/从模式)

    类似mysql的master-slave模式一样,redis的master-slave可以提升系统的可用性,master节点写入cache后,会自动同步到slave上. 环境: master node ...

  8. Eval is Devil-MongoDB master/slave上运行Eval遇到的问题

    随便写一句,以免有跟我一样的人遇到这个问题. 驱动版本:MongoDB C# Driver 1.7.0 当在Master/Slave集群上使用Eval的时候,Eval操作只会在Master结点上运行, ...

  9. show master/slave status求根溯源

    show master/slave status分别是查看主数据库以及副数据库的状态,是一种能查看主从复制运行情况的方式. 这里仅仅讨论linux下的nysql5.7.13版本的执行情况 一.show ...

随机推荐

  1. shiro登陆权限验证

    一>引入shirojar包 <!-- shiro登陆权限控制 -->        <dependency>            <groupId>org. ...

  2. THREE.js代码备份——webgl - materials - cube refraction [balls](以上下左右前后6张图片构成立体场景、透明球体效果)

    <!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - ma ...

  3. C# MVC 返回html内容

    var ss = Server.MapPath(""); //C:\Users\Administrator\Desktop\Csharp测试程序\TestMVC\TestMVC s ...

  4. 测试模式 windows2008 内部版本7601

    win server 2008 r2 enterprise 64位系统. 最近手贱,对服务器进行了一下更新,结果傻叉了,这是什么鬼,明明显示已经激活的,但就是有这么一串碍眼的字幕. 电脑右下角居然出现 ...

  5. Day 25 面向对象

    面向对象基础 面向对象编程 面向过程编程:类似于工厂的流水线 优点:逻辑清晰 缺点:扩展性差 面向对象编程:核心是对象二字,对象属性和方法的集合体,面向对象编程就是一堆对象交互 优点:扩展性强 缺点: ...

  6. vue http请求 vue自带的 vue-resource

    vue-resource安装 npm install vue-resource --save-dev 配置 在main.js中引入插件 //Resource 为自定义名 vue-resource 为插 ...

  7. eas之日志文件夹

    F:\ThisIs_MyWork\kingdee\eas\server\profiles\server1\logs 服务端的日志文件夹    F:\ThisIs_MyWork\kingdeecusto ...

  8. CSS定位相关

    CSS display:inline和float:left两者区别 ①display:inline:任何不是块级元素的可见元素都是内联元素.其表现的特性是“行布局”形式!(行布局:其表现形式始终以行进 ...

  9. Spring Cloud-hystrix(六)

    作用 防止 多个服务相互交互时某个服务运行缓慢导致调用方线程挂起,高并发情况下 导致挂起线太多 引起调用方的服务不可用 能够在服务发生故障或者通过断路器监控向调用方返回一个错误 而不是长时间的等待 S ...

  10. 【ACM】hdu_3782_xxx定律_201308011521

    xxx定律Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...