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 ...
随机推荐
- js-事件处理(重点)
1:各种常用事件: 2:简单用法: <body onLoad="javascript:alert('hello world');" onUnload="javasc ...
- c# ado.net eftity framework 返回多表查询结果
public static IQueryable GetWeiXinTuWenList() { using (var Model = new Model.WeiXinEntities()) { var ...
- Cache-Control 机制是为浏览器定制的?
Cache-Control 机制是为浏览器定制的?
- MVC控制器返回值
public ActionResult Index(string id)//主页 //参数string searchString 访问方式为index?searchString=xxxx .参数str ...
- Redis 通用key操作命令
1.在redis里面允许模糊查询key,有3个通配符:*,?,[]. *:通配任意字符 ?:通配单个字符 []:通配中括号内的某个字符 例如: 2.randomKey 随机返回所有key中的某个 3. ...
- react新版本生命周期
给componentWillMount componentWillReceiveProps componentWillUpdate生命周期加上UNSAFE_前缀,表明其不安全性,并将在未来版本将其移除 ...
- Java导出Excel(附完整源码)
导出excel是咱Java开发的必备技能啦,之前项目有这个功能,现在将其独立出来,分享一下.所用技术就是SpringBoot,然后是MVC架构模式.废话不多说,直接上代码了,源码点末尾链接就可以下载. ...
- 使用JAVA写一个简单的日历
JAVA写一个简单的日历import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateF ...
- jupyter notebook主目录修改
转自http://blog.csdn.net/c437yuyang/article/details/54836303 1.打开 cmd 输入命令 jupyter notebook --generate ...
- Leetcode 动态规划 - 简单
1. 最大子序和 (53) 给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输 ...