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 ...
随机推荐
- objectdatasouce的温故
在做ecxel的时候,需要前台做一个联动的效果. 记录一下这个数据源的用法,大学时候用的,忘得差不多了 首先就是往页面拖拽一个objectdatasouce的控件 然后配置数据源: 选择业务对象(其实 ...
- **ML : ML中的最优化方法
前言: 在机器学习方法中,若模型理解为决策模型,有些模型可以使用解析方法.不过更一般的对模型的求解使用优化的方法,更多的数据可以得到更多的精度. AI中基于归纳的方法延 ...
- 【sqli-labs】 less13 POST - Double Injection - Single quotes- String -twist (POST型单引号变形双注入)
报错 闭合掉括号 这关登录成功之后不显示登录的用户名密码了
- Fish:Linux中比bash或zsh更好用的Shell
Fish是一个智能且用户友好的命令行shell,适用于macOS,Linux和其他家族.fish包含语法突出显示.根据你键入字符自动提示autosuggest-as-type和花式选项卡完成等功能,无 ...
- Windows server 2008R2系统登录密码破解
服务器密码忘记,或者被恶意修改,系统被入侵,都是很让人烦心的事情,我试过很多方法,包括使用PE工具删除C盘Windows\System\config里面的SAM文件,可是过程都相当华美,结果都相当杯具 ...
- apicloud iphoneX底部虚拟键盘遮挡
1.首先,底部的高不能写死. 2. var footer = $api.byId('footer'); $api.fixTabBar(footer);这句应该写在 footerHeight = $ap ...
- Bamboo Django Celery定时任务和时间设置
1.Celery加入定时任务 Celery除了可以异步执行任务之外,还可以定时执行任务.在实例代码的基础上写个测试方法: 1 #coding:utf-8 2 from celery.task.sche ...
- 洛谷P1090 合并果子【贪心】
在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆.多多决定把所有的果子合成一堆. 每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和.可以看出,所 ...
- 在LINUX系统上通过LINUX命令安装mysql数据库和JDK环境
此示例通过Winscp工具和Xshell已验证通过 安装示例1: 在Centos6.5上安装JDK-10.0.2版本 检查LINUX系统是否有自带或者安装过的JDK版本:Java -version 查 ...
- Yii2验证码使用教程
控制器代码 public function actions() { return [ 'captcha' => [ 'class' => 'yii\captcha\CaptchaActio ...