MongoDB Master/Slaver配置
发表于:2026-10-31 作者:千家信息网编辑
千家信息网最后更新 2026年10月31日,接MongoDB快速入门本文主要介绍MongoDB Master/Slaver配置首先创建Mongo Master/home/hrj/mongodb-linux-i686-static-1.6.5/b
千家信息网最后更新 2026年10月31日MongoDB Master/Slaver配置接MongoDB快速入门
本文主要介绍MongoDB Master/Slaver配置
至此Master/Slaver大致调试成功。在这里大致提一下Master/Slaver特别参数:
Master
--master master模式
--oplogSize arg size limit (in MB) for op log
Slave
--slave slave模式
--source arg source指定master位置
--only arg 单独指定备份某一database
--slavedelay arg 指定与Master延迟时间(秒)
--autoresync 当Slave数据过时后自动重连
特别推荐:
很可能会出现Master服务器Down掉之后,需要用Slave服务器来顶替Master提供服务器的情况,这个时候就需要做如下操作:
本文主要介绍MongoDB Master/Slaver配置
- 首先创建Mongo Master/home/hrj/mongodb-linux-i686-static-1.6.5/bin/mongod --master --dbpath /home/hrj/mongodb_data --auth --maxConns 50 --port 6688
- 其次创建Mongo Slaver/home/hrj/mongodb-linux-i686-static-1.6.5/bin/mongod --slave --source myna5.sds.cnb.yahoo.com:6688 --auth --maxConns 50 --auth --port 6689 --fastsync --autoresync --dbpath /home/hrj/mongodb_slave_data
- 创建Master、Slaver帐号~/mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.0.1:6689 ### 在Slaver上创建帐号
> use local
switched to db local
> db.addUser('hrj','xxx')
{
"_id" : ObjectId("4d6f6527013fcbcc74575c20"),
"user" : "hrj",
"readOnly" : false,
"pwd" : "b27edaa5a8858aa3d46b60698fce1359"
}
~/mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.0.1:6688 ### 在Master上创建帐号
MongoDB shell version: 1.6.5
connecting to: 127.0.0.1:6688/test
>use local
switched to db local
> db.addUser('hrj','xxx')
{
"_id" : ObjectId("4d6f6527013fcbcc74575c20"),
"user" : "hrj",
"readOnly" : false,
"pwd" : "b27edaa5a8858aa3d46b60698fce1359"
}
>use test ###添加帐号认证
switched to db local
> db.auth('hrj','xxx') - 向Master加载数据,测试Slaver是否正常同步###Master
~/mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.0.1:6688
MongoDB shell version: 1.6.5
connecting to: 127.0.0.1:6688/test
> db.foo.save({'mongodb':'hello world'}) ###导入数据
> db.foo.find() ###查询数据
{ "_id" : ObjectId("4d6f72c6d807e8561b0f3db5"), "mongodb" : "hello world" }
###Slaver
~/mongodb-linux-i686-static-1.6.5/bin/mongo 127.0.0.1:6689
MongoDB shell version: 1.6.5
connecting to: 127.0.0.1:6689/test
> db.foo.find() ###查询Slaver同步数据
{ "_id" : ObjectId("4d6f72c6d807e8561b0f3db5"), "mongodb" : "hello world" }
> db.foo.save({'mongodb':'hello world test 1'}) ###Slaver导入数据,提示"not master"
not master
至此Master/Slaver大致调试成功。在这里大致提一下Master/Slaver特别参数:
Master
--master master模式
--oplogSize arg size limit (in MB) for op log
Slave
--slave slave模式
--source arg source指定master位置
--only arg 单独指定备份某一database
--slavedelay arg 指定与Master延迟时间(秒)
--autoresync 当Slave数据过时后自动重连
特别推荐:
很可能会出现Master服务器Down掉之后,需要用Slave服务器来顶替Master提供服务器的情况,这个时候就需要做如下操作:
- 停止Slave进程(mongod)
- 删除Slave数据目录中的local.*
- 以--master模式启动Slave
数据
帐号
服务器
模式
服务
时候
同步
查询
配置
过时
成功
位置
参数
备份
情况
时间
特别推荐
目录
至此
进程
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网品科技
万易互联网科技
互联网科技作文
卓越科技(互联网 )
安徽鑫晟辉互联网科技
九亚互联网科技
智慧科技互联网
北京禾田雨橡互联网科技
互联网科技英文翻译
互联网养老 桔豆科技
互联网科技公司需要的职位
上海宁丞科技互联网
湖南一路畅行互联网科技
东莞新华互联网科技学校
中和天地互联网科技有限公司
互联网第三次科技革命特征
图游互联网科技
下一代互联网重大应用科技园
山东大美朱楼互联网科技有限公司
长沙易易互联网科技有限公司
花魁咖啡
多迪互联网科技有限公司
互联网科技股午盘股票涨跌
互联网科技实习生岗位职责
互联网和黑科技的看法
内蒙古九一互联网科技
东莞新华互联网科技学校
云南互联网科技学费
互联网科技品牌
互联网科技创业有什么好项目