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 ...
随机推荐
- 【SQL】字符型函数
1. ASCII ASCII(American Standard Code for Information Interchange,美国信息交换标准代码)是基于拉丁字母的一套电脑编码系统. 1) 返回 ...
- 使用replace pioneer批量修改文件名
shell的正则表达式还是很难记忆的,也没有沉静的心情看文档,于是使用了replace pioneer. 1. 启动replace pioneer,Tools->batch runner , ...
- mvc登录授权特性
public class CommonAuthorize : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContex ...
- Python匿名函数/排序函数/过滤函数/映射函数/递归/二分法
一. lamda匿名函数 为了解决一些简单的需求而设计的一句话函数 # 计算n的n次方 def func(n): return n**n print(func(10)) f = lambda n: n ...
- S-HR二开基础
检测是否某个类部署上去了:http://10.3.0.115:6888/easportal/tools/getclassurl.jsp?className=com.kingdee.eas.hr.ser ...
- Coloring Flame Graphs: Code Hues
转自:http://www.brendangregg.com/blog/2017-07-30/coloring-flamegraphs-code-type.html I recently improv ...
- 函数(day08)
C语言里可以采用分组的方式管理语句 每个语句分组叫做一个函数 多函数程序执行的时候时间分配情况必须 遵守以下规则 .整个程序的执行时间被划分成几段,每段 时间都被分配给一个函数使用 .不同时间段不能互 ...
- [luogu2624 HNOI2008]明明的烦恼 (prufer+高精)
传送门 Solution 根据prufer序列做的题,具体可以看这里 还知道了一种避免高精除的方法quq Code #include <cmath> #include <cstdio ...
- [luogu2474 SCOI2008]天平(floyd差分约束)
传送门 Solution 由于重量只有三种情况,那么想到用差分约束. 由于范围比较小,想到可以floyed求差分约束,暴力求天平另一边 Code #include <cstdio> #in ...
- PHP学习总结(13)——PHP入门篇之常量
1.什么是常量 什么是常量?常量可以理解为值不变的量(如圆周率):或者是常量值被定义后,在脚本的其他任何地方都不可以被改变.PHP中的常量分为自定义常量和系统常量(后续小节会详细介绍). 自定义常量是 ...