MongoDB Master-Slave cluster with authentication setup
Master Server
create mongo db folder with sub folders like data, conf, && log
mkdir-p/opt/mongo/datamkdir-p/opt/mongo/confmkdir-p/opt/mongo/logcreate a keyfile to secure mongo DB custer traffic. scp this file to slave server
cd/srv/mongodb/openssl rand -base64 741 >>mongo-keychmod700 mongo-keyvi /opt/mongo/conf/master.conf
dbpath=/opt/mongo/datalogpath=/opt/mongo/log/mongodb.loglogappend=truefork=trueport=27017oplogSize=2048- start mongo with command mongod --config /opt/mongo/conf/master.conf
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"}]}modify the conf file and add the last 3 lines into the file
dbpath=/opt/mongo/datalogpath=/opt/mongo/log/mongodb.loglogappend=truefork=trueport=27017oplogSize=2048master=trueauth=truekeyFile=/opt/mongo/mongo-keyrestart mongo with new config file
mongod --config/opt/mongo/conf/master.conf --shutdownmongod --config/opt/mongo/conf/master.conf
Slave Server
- create mongo db folder with sub folders like data, conf, && log; same as master
copy the keyfile to mongo folder and modify the slave.conf
dbpath=/opt/mongo/datalogpath=/opt/mongo/log/mongodb.loglogappend=truefork=trueport=27017oplogSize=2048slave=trueauth=truekeyFile=/opt/mongo/mongo-keysource= [master ip]:[port]start slave server
mongod --config/opt/mongo/conf/slave.conflogin 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 testswitched to db test> db.products.insert( { item: "card", qty: 15 } )WriteResult({ "nInserted" : 1 })> show collectionsproducts |
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 testswitched to db test> db.dropDatabase(){ "dropped" : "test", "ok" : 1 }
|
MongoDB Master-Slave cluster with authentication setup的更多相关文章
- mongodb - Master Slave Replication
master-slave复制模式大多场景下都被replicat sets代替.官方也建议使用replicat sets. master-slave复制不支持自动failover. master-sla ...
- MongoDB学习笔记——Master/Slave主从复制
Master/Slave主从复制 主从复制MongoDB中比较常用的一种方式,如果要实现主从复制至少应该有两个MongoDB实例,一个作为主节点负责客户端请求,另一个作为从节点负责从主节点映射数据,提 ...
- Redis master/slave,sentinel,Cluster简单总结
现在互联网项目中大量使用了redis,本文著主要分析下redis 单点,master/slave,sentinel模式.cluster的一些特点. 一.单节点模式 单节点实例还是比较简单的,平时做个测 ...
- Mongodb集群——master/slave
集群的配置 (本测试放于同一台机器进行配置,所以IP地址一样,如果是在不同的服务器上更换IP便可以) 1.目录结构 拷贝两份mongodb到/home/scotte.ye/mongo1 ...
- 转】MongoDB主从复制实验 master/slave
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/4/ 感谢! Posted: May 31, 2013 Ta ...
- 【摘录】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 ...
- redis 学习笔记(3)-master/slave(主/从模式)
类似mysql的master-slave模式一样,redis的master-slave可以提升系统的可用性,master节点写入cache后,会自动同步到slave上. 环境: master node ...
- Eval is Devil-MongoDB master/slave上运行Eval遇到的问题
随便写一句,以免有跟我一样的人遇到这个问题. 驱动版本:MongoDB C# Driver 1.7.0 当在Master/Slave集群上使用Eval的时候,Eval操作只会在Master结点上运行, ...
- show master/slave status求根溯源
show master/slave status分别是查看主数据库以及副数据库的状态,是一种能查看主从复制运行情况的方式. 这里仅仅讨论linux下的nysql5.7.13版本的执行情况 一.show ...
随机推荐
- 【Oracle】解锁用户
登录oracle数据库时有时会显示ERROR: ORA-28000: the account is locked,这是因为所登录的账号被锁定了. 解决办法: sqlplus / as sysdba; ...
- Equals相關的一些要點
什麽時候需要覆蓋Equals? 自定義的值類型需要覆蓋,因爲框架默認的實現是基於反射的,效率不高. 自定義的引用類型要根據業務需要來決定是否提供覆蓋. 什麽時候需要覆蓋operator==()? ...
- mysql安装包下载地址
1.打开mysql官网 :https://dev.mysql.com/ 2.选择 downlad-->windows-->MySQL Installer -->滑动至页面底部,选择第 ...
- C语言编程-9_4 字符统计
输入一个字符串(其长度不超过81),分别统计其中26个英文字母出现的次数(不区分大.小写字母),并按字母出现次数从高到低排序,若次数相同,按字母顺序排列.字母输出格式举例,例如:A-3,表示字母A出现 ...
- 【airtest, python】报错:requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')),解决方法如下
环境及设备 mac, xcode , iphonex 问题 最近出现一个让人费解的问题,airtest 没跑多长时间,服务就断掉,而且总是报“requests.exceptions.Connectio ...
- 自编码器----Autoencoder
一.自编码器:降维[无监督学习] PCA简介:[线性]原矩阵乘以过渡矩阵W得到新的矩阵,原矩阵和新矩阵是同样的东西,只是通过W换基. 自编码: 自动编码器是一种无监督的神经网络模型,它可以学习到输入数 ...
- javascript实现:在N个字符串中找出最长的公子串
'use strict' module.exports = function 找出最长公子串 (...strings) { let setsOfSubstrings = [] strings.redu ...
- Git 基础教程 之 撤销修改
Git跟踪并管理的是修改,而非文件.每次修改,如果不用git add到暂存区,那就不会加入到commit中, 要么全部改完后,再add → commit :要么改一点,就add → commit. 撤 ...
- MYSQL(一) 简单语法
MYSQL(一) 简单语法 1.默认约束:mysql里面DEFAULT关键字后面是不用加括号的 --1.1 创建数据库 mysql> create database holly; Query O ...
- 提高生产力:文件和IO操作(ApacheCommonsIO-汉化分享)
复制.移动.删除.比较.监控.文件读写 等文件和IO操作是编程中比较常用的功能. 幸运的是,Apache Commons IO等开源组件已经帮我们实现了. 我们可以不用重复 ...