代码改变世界

mongodb - Master Slave Replication

  abce  阅读(1264)  评论(0编辑  收藏  举报

master-slave复制模式大多场景下都被replicat sets代替。官方也建议使用replicat sets。

master-slave复制不支持自动failover。

master-slave部署

1.启动master节点

1
# ./mongod --master --dbpath /mongodb320/master --port=27017

启动后,会创建local.oplog.$main集合,存放操作日志

2.启动slave节点

1
2
3
4
5
6
7
8
9
10
11
12
13
# ./mongod --slave --source 12.12.12.195:27017 --dbpath /mongodb320/slave --port=27018
 
或者启动后设置
# ./mongod --dbpath /mongodb320/slave --port=27018
# ./mongo --port=27018
> use localu
switched to db local
> db.sources.find()
> db.sources.insert({"host":"12.12.12.195:27017"})db.sources.insert({"host":"12.12.12.195:27017"})
WriteResult({ "nInserted" : 1 })
> db.sources.find()
{ "_id" : ObjectId("56e77cfa282f6e26c2c2b5c8"), "host" : "12.12.12.195:27017" }
>

3.查看master-slave状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#登陆master节点
> rs.printReplicationInfo()
configured oplog size:   1023.9609375MB
log length start to end: 904secs (0.25hrs)
oplog first event time:  Tue Mar 15 2016 10:45:17 GMT+0800 (CST)
oplog last event time:   Tue Mar 15 2016 11:00:21 GMT+0800 (CST)
now:                     Tue Mar 15 2016 11:00:27 GMT+0800 (CST)
 
#登陆slave节点
> rs.printReplicationInfo()
this is a slave, printing slave replication info.
source: 12.12.12.195:27017
        syncedTo: Tue Mar 15 2016 11:04:21 GMT+0800 (CST)
        6 secs (0 hrs) behind the freshest member (no primary available at the moment)
> rs.printSlaveReplicationInfo()rs.printSlaveReplicationInfo()
source: 12.12.12.195:27017
        syncedTo: Tue Mar 15 2016 11:16:21 GMT+0800 (CST)
        4 secs (0 hrs) behind the freshest member (no primary available at the moment)
>

 

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示