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. 连接SQL Server数据库语法

    下面介绍一下连接Sqlserver数据库.把连接Sqlserver数据库封装为一个方法,以便直接调用,而不需写重复代码. import java.sql.Connection; import java ...

  2. 三维重建:多点透视cvSolvePNP的替代函数(Code)

           在调试JNI程序时,所有的Shell都已经加载完成,而唯一真正核心的cv::SolvePnP却不能在JNI里面获得通行证,经过反复测试都不能运行,因此只能忍痛舍弃,自行编写一个具有相 ...

  3. jquery的attr和prop

    注意不同版本的attr和prop,attr适用于自定义dom值,prop适用于带有固有属性

  4. drf04 drf视图类

    REST framework 提供了众多的通用视图基类与扩展类,以简化视图的编写. 1.2个视图基类 1.1. APIView rest_framework.views.APIView APIView ...

  5. BZOJ 4195: [Noi2015]程序自动分析 并查集 + 离散化 + 水题

    TM 读错题了...... 我还以为是要动态询问呢,结果是统一处理完了再询问...... 幼儿园题,不解释. Code: #include<bits/stdc++.h> #define m ...

  6. 13、Next Item Recommendation with Self-Attention---自注意力+CML

    一.摘要: 自注意力机制------从用户历史交互中推断出项目-项目关系.学习每个项目的相对权重[用来学习用户的暂时兴趣表示] 二. 模型: 一部分是用于建模用户短期意图的自注意力机制,一部分是建模用 ...

  7. svn版本库更新后自动同步到www

    注意:www目录一定要用SVN服务器 checkout出Repositories的代码 步骤: (1)新建www根目录 mkdir -p /data/www/lehuo (2)在www根目录下检出(c ...

  8. node源码详解(三)

    本作品采用知识共享署名 4.0 国际许可协议进行许可.转载保留声明头部与原文链接https://luzeshu.com/blog/nodesource3 本博客同步在https://cnodejs.o ...

  9. python第十周:进程、协程、IO多路复用

    多进程(multiprocessing): 多进程的使用 multiprocessing是一个使用类似于线程模块的API支持产生进程的包. 多处理包提供本地和远程并发,通过使用子进程而不是线程有效地侧 ...

  10. QT中的信号槽

    只有继承了QObject类的类,才具有信号槽的能力.所以,为了使用信号槽,必须继承QObject. 凡是QObject类(不管是直接子类还是间接子类),都应该在第一行代码写上Q_OBJECT. 不管是 ...