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. 【Oracle】解锁用户

    登录oracle数据库时有时会显示ERROR: ORA-28000: the account is locked,这是因为所登录的账号被锁定了. 解决办法: sqlplus / as sysdba; ...

  2. Equals相關的一些要點

    什麽時候需要覆蓋Equals? 自定義的值類型需要覆蓋,因爲框架默認的實現是基於反射的,效率不高. 自定義的引用類型要根據業務需要來決定是否提供覆蓋.    什麽時候需要覆蓋operator==()? ...

  3. mysql安装包下载地址

    1.打开mysql官网 :https://dev.mysql.com/ 2.选择 downlad-->windows-->MySQL Installer -->滑动至页面底部,选择第 ...

  4. C语言编程-9_4 字符统计

    输入一个字符串(其长度不超过81),分别统计其中26个英文字母出现的次数(不区分大.小写字母),并按字母出现次数从高到低排序,若次数相同,按字母顺序排列.字母输出格式举例,例如:A-3,表示字母A出现 ...

  5. 【airtest, python】报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')),解决方法如下

    环境及设备 mac, xcode , iphonex 问题 最近出现一个让人费解的问题,airtest 没跑多长时间,服务就断掉,而且总是报“requests.exceptions.Connectio ...

  6. 自编码器----Autoencoder

    一.自编码器:降维[无监督学习] PCA简介:[线性]原矩阵乘以过渡矩阵W得到新的矩阵,原矩阵和新矩阵是同样的东西,只是通过W换基. 自编码: 自动编码器是一种无监督的神经网络模型,它可以学习到输入数 ...

  7. javascript实现:在N个字符串中找出最长的公子串

    'use strict' module.exports = function 找出最长公子串 (...strings) { let setsOfSubstrings = [] strings.redu ...

  8. Git 基础教程 之 撤销修改

    Git跟踪并管理的是修改,而非文件.每次修改,如果不用git add到暂存区,那就不会加入到commit中, 要么全部改完后,再add → commit :要么改一点,就add → commit. 撤 ...

  9. MYSQL(一) 简单语法

    MYSQL(一) 简单语法 1.默认约束:mysql里面DEFAULT关键字后面是不用加括号的 --1.1 创建数据库 mysql> create database holly; Query O ...

  10. 提高生产力:文件和IO操作(ApacheCommonsIO-汉化分享)

    复制.移动.删除.比较.监控.文件读写 等文件和IO操作是编程中比较常用的功能.        幸运的是,Apache Commons IO等开源组件已经帮我们实现了.        我们可以不用重复 ...