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 ...
随机推荐
- Embedded之Makefile
1 Header files The header files are empty, so you can create them with touch: $ touch a.h $ touch b. ...
- Java_Web之神奇的Ajax
为什么使用Ajax? 无刷新:不刷新整个页面,只刷新局部 无刷新的好处 提供类似C/S的交互效果,操作更方面 只更新部分页面,有效利用带宽 什么是Ajax? XMLHttpRequest常用方 ...
- 使用JAVA写一个简单的日历
JAVA写一个简单的日历import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateF ...
- Android 性能测试初探(三)
书接上文 Android 性能测试初探(二) 本文接着往下聊,今天主聊 CPU 及 内存 看到这两个名词,做过PC性能测试的就比较熟悉了,同样的性能测试关注点 :) 首先说说内存,移动端关注的是内存消 ...
- jQuery默认select选择第一个元素
$("#id option:first").prop("selected", 'selected');
- 想要远程服务器长时间挂机不断开ssh连接的技巧
使用top命令挂着就好了,top命令执行的“查看系统进程和资源占用”的任务会一直输出动态的数据,一直有数据传输就不会因为长时间挂机而断开ssh链接了,尤其针对于海外服务器,因为高延迟经常出现挂机久了自 ...
- safari浏览器click事件要点击两次才有响应出现闪烁
闪烁问题 由于在iOS Safari上click事件存在300ms响应延时,所以为touch事件添加样式,会和click事件默认样式叠加而产生闪烁问题. 因为ios safari浏览器中对触摸事件的响 ...
- 爬虫系列(十二) selenium的基本使用
一.selenium 简介 随着网络技术的发展,目前大部分网站都采用动态加载技术,常见的有 JavaScript 动态渲染和 Ajax 动态加载 对于爬取这些网站,一般有两种思路: 分析 Ajax 请 ...
- tp5 异常处理
=== <?php/** * Created by PhpStorm. * User: 14155 * Date: 2018/11/10 * Time: 0:26 */ namespace ap ...
- dubbo-dubboAdmin安装(一)
简介 Dubbo是什么? dubbo是阿里开源的分布式服务治理框架,对服务的负载均衡,权重,监控,路由规则,禁用启用的管理,以及服务的自动注册和发现 分布式架构下面临问题 在分布式架构下,我们会将一个 ...