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】字符型函数

    1. ASCII ASCII(American Standard Code for Information Interchange,美国信息交换标准代码)是基于拉丁字母的一套电脑编码系统. 1) 返回 ...

  2. 使用replace pioneer批量修改文件名

    shell的正则表达式还是很难记忆的,也没有沉静的心情看文档,于是使用了replace pioneer. 1.  启动replace pioneer,Tools->batch runner  , ...

  3. mvc登录授权特性

    public class CommonAuthorize : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContex ...

  4. Python匿名函数/排序函数/过滤函数/映射函数/递归/二分法

    一. lamda匿名函数 为了解决一些简单的需求而设计的一句话函数 # 计算n的n次方 def func(n): return n**n print(func(10)) f = lambda n: n ...

  5. S-HR二开基础

    检测是否某个类部署上去了:http://10.3.0.115:6888/easportal/tools/getclassurl.jsp?className=com.kingdee.eas.hr.ser ...

  6. Coloring Flame Graphs: Code Hues

    转自:http://www.brendangregg.com/blog/2017-07-30/coloring-flamegraphs-code-type.html I recently improv ...

  7. 函数(day08)

    C语言里可以采用分组的方式管理语句 每个语句分组叫做一个函数 多函数程序执行的时候时间分配情况必须 遵守以下规则 .整个程序的执行时间被划分成几段,每段 时间都被分配给一个函数使用 .不同时间段不能互 ...

  8. [luogu2624 HNOI2008]明明的烦恼 (prufer+高精)

    传送门 Solution 根据prufer序列做的题,具体可以看这里 还知道了一种避免高精除的方法quq Code #include <cmath> #include <cstdio ...

  9. [luogu2474 SCOI2008]天平(floyd差分约束)

    传送门 Solution 由于重量只有三种情况,那么想到用差分约束. 由于范围比较小,想到可以floyed求差分约束,暴力求天平另一边 Code #include <cstdio> #in ...

  10. PHP学习总结(13)——PHP入门篇之常量

    1.什么是常量 什么是常量?常量可以理解为值不变的量(如圆周率):或者是常量值被定义后,在脚本的其他任何地方都不可以被改变.PHP中的常量分为自定义常量和系统常量(后续小节会详细介绍). 自定义常量是 ...