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. 复习java基础第二天(异常处理)

    一.常见的异常类型: public class TestException { public static void main(String[] args) { int i = 10; //数学异常: ...

  2. 释放Win8.1 WinSxS冗余更新,微软Dism来解决

    命令提示符(管理员) dism /online /Cleanup-Image /StartComponentCleanup /ResetBase 有些文章不建议使用 /RestBase,可能会有风险.

  3. (转)基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模块的处理

    http://www.cnblogs.com/wuhuacong/p/4757984.html 最近一直很多事情,博客停下来好久没写了,整理下思路,把最近研究的基于Metronic的Bootstrap ...

  4. C++调用Matlab函数求特征值

    最近需要用到C++和Matlab的混编,记录一下学习过程~ 要实现的是调用Matlab函数,求矩阵前k个最小的特征值及其特征向量. //C++ #include "engine.h" ...

  5. eoLinker-AMS开源版JAVA版本正式发布

    eoLinker-AMS开源版JAVA版本正式发布! eoLinker深感广大开发者的支持与厚爱,我们一直在努力为大家提供更多更好的接口服务.截止至2018年4月3日,eoLinker-AMS 开源版 ...

  6. 再谈应用环境下的 TIME_WAIT 和 CLOSE_WAIT

    转自:http://blog.csdn.net/shootyou/article/details/6622226 昨天解决了一个 HttpClient 调用错误导致的服务器异常,具体过程如下: htt ...

  7. Nginx Rewrite(伪静态)

    一.作用: 实现URL地址改写. 二.语法: 例:rewrite ^/(.*) http://bbs.wangguangtao.com/$1 permanent; 注:应用位置server.loeat ...

  8. 11. IDEA 在同一工作空间创建多个项目

    1.创建项目 二..创建工作空间 JavaWorkspace 1.File-> New Project -> 创建工作空间 JavaWorkspace,并 顺便创建项目 JavaOne 2 ...

  9. ecshop ad调用指定广告的方法 邓士鹏

      在include/lib_goods.php文件下面新增:function getads($cat,$num){$time = gmtime();$sql = "SELECT * FRO ...

  10. Python 实现把 .cvs 文件保存为 Excel 文件

    # 导入可以把 CVS 转换为 Excel 的外部模块 import pandas as pd # 读出 csv 文件的内容 csv = pd.read_csv('Data.csv', encodin ...