MongoDB Master-Slave cluster with authentication setup
Master Server
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
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
vi /opt/mongo/conf/master.conf
dbpath=
/opt/mongo/data
logpath=
/opt/mongo/log/mongodb
.log
logappend=
true
fork=
true
port=27017
oplogSize=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/data
logpath=
/opt/mongo/log/mongodb
.log
logappend=
true
fork=
true
port=27017
oplogSize=2048
master=
true
auth=
true
keyFile=
/opt/mongo/mongo-key
restart mongo with new config file
mongod --config
/opt/mongo/conf/master
.conf --
shutdown
mongod --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/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]
start slave server
mongod --config
/opt/mongo/conf/slave
.conf
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的更多相关文章
- 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 Server实现用户注册
用SQL Server注册用户,通过页面输入注册信息,存储到数据库. <form action="zhuChe.jsp" method="post" on ...
- (转)C#开发微信门户及应用(5)--用户分组信息管理
http://www.cnblogs.com/wuhuacong/p/3695351.html 在上个月的对C#开发微信门户及应用做了介绍,写过了几篇的随笔进行分享,由于时间关系,间隔了一段时间没有继 ...
- appium的滑动
#coding = utf-8from appium import webdriverimport time'''1.手机类型2.版本3.手机的唯一标识 deviceName4.app 包名appPa ...
- 11.【Linq】
11.2.4 Cast . OfType 和显式类型的范围变量 这两个操作符很相似:都可以处理任意非类型化的序列(它们是非泛型 IEnumerable 类的扩展方法),并返回强类型的序列. Cast ...
- 关于vcruntime140D.dll丢失问题
电脑磁盘占用率100%,又检测出硬盘磁道坏了,要么装win7,要么换个SSD,无奈重装环境. 遇到这个问题,之前的电脑就遇到过,网上交的下载这个文件装到C盘Windows的SysWOW64,对于实验室 ...
- qbxt 考前集训 Day1
立方数(cubic) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK定义了一个数叫“立方数”,若一个数可以被写作是一个正整数的3次方,则这个数就是立方数 ...
- 在微信小程序里使用 watch 和 computed
在开发 vue 的时候,我们可以使用 watch 和 computed 很方便的检测数据的变化,从而做出相应的改变,但是在小程序里,只能在数据改变时手动触发 this.setData(),那么如何给小 ...
- luogu P4725 多项式对数函数 (模板题、FFT、多项式求逆、求导和积分)
手动博客搬家: 本文发表于20181125 13:25:03, 原地址https://blog.csdn.net/suncongbo/article/details/84487306 题目链接: ht ...
- 洛谷 P2010 回文日期
Noip2016普及组T2 题目描述 在日常生活中,通过年.月.日这三个要素可以表示出一个唯一确定的日期. 牛牛习惯用8位数字表示一个日期,其中,前4位代表年份,接下来2位代表月 份,最后2位代表日期 ...
- 【ACM】nyoj_103_A+BII_201307291022
A+B Problem II时间限制:3000 ms | 内存限制:65535 KB 难度:3描述 I have a very simple problem for you. Given two ...