mongodb - Replication Set搭建过程
2016-03-15 13:51 abce 阅读(820) 评论(0) 编辑 收藏 举报1.创建目录
1 2 3 4 | mkdir -p /mongodb/data/r1 mkdir -p /mongodb/data/r2 mkdir -p /mongodb/data/r3 mkdir -p /mongodb/mlog |
2.启动三个实例,并声明实例属于复制集
1 2 3 | . /mongod --dbpath /mongodb/data/r1 --logpath /mongodb/mlog/r1 .log --fork --port 27017 --replSet ybb --smallfiles . /mongod --dbpath /mongodb/data/r2 --logpath /mongodb/mlog/r2 .log --fork --port 27018 --replSet ybb --smallfiles . /mongod --dbpath /mongodb/data/r3 --logpath /mongodb/mlog/r3 .log --fork --port 27019 --replSet ybb --smallfiles |
3.复制集初始化
这一步初始化的复制集只是包含当前节点
1 2 3 4 5 6 7 | # ./mongo --port=27017 > rs.initiate() { "info2" : "no configuration specified. Using a default configuration for the set" , "me" : "cc.example.com:27017" , "ok" : 1 } |
4.验证复制集初始化配置
这一步初始化的复制集只是包含当前节点
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | ybb:OTHER> rs.conf() { "_id" : "ybb" , "version" : 1, "protocolVersion" : NumberLong(1), "members" : [ { "_id" : 0, "host" : "cc.example.com:27017" , "arbiterOnly" : false , "buildIndexes" : true , "hidden" : false , "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true , "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 } } } ybb:PRIMARY> |
5.添加其它节点
1 2 3 4 5 | ybb:PRIMARY> rs.add( "cc.example.com:27018" )rs.add( "cc.example.com:27018" ) { "ok" : 1 } ybb:PRIMARY> rs.add( "cc.example.com:27019" )rs.add( "cc.example.com:27019" ) { "ok" : 1 } ybb:PRIMARY> |
6.检查复制集的状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ybb:PRIMARY> rs.status()rs.status() { "set" : "ybb" , "date" : ISODate( "2016-03-15T05:26:06.682Z" ), "myState" : 1, "term" : NumberLong(1), "heartbeatIntervalMillis" : NumberLong(2000), "members" : [ { "_id" : 0, "name" : "cc.example.com:27017" , "health" : 1, "state" : 1, "stateStr" : "PRIMARY" , "uptime" : 482, "optime" : { "ts" : Timestamp(1458019522, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate( "2016-03-15T05:25:22Z" ), "electionTime" : Timestamp(1458019202, 2), "electionDate" : ISODate( "2016-03-15T05:20:02Z" ), "configVersion" : 3, "self" : true }, { "_id" : 1, "name" : "cc.example.com:27018" , "health" : 1, "state" : 2, "stateStr" : "SECONDARY" , "uptime" : 47, "optime" : { "ts" : Timestamp(1458019522, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate( "2016-03-15T05:25:22Z" ), "lastHeartbeat" : ISODate( "2016-03-15T05:26:04.822Z" ), "lastHeartbeatRecv" : ISODate( "2016-03-15T05:26:05.826Z" ), "pingMs" : NumberLong(0), "syncingTo" : "cc.example.com:27017" , "configVersion" : 3 }, { "_id" : 2, "name" : "cc.example.com:27019" , "health" : 1, "state" : 2, "stateStr" : "SECONDARY" , "uptime" : 43, "optime" : { "ts" : Timestamp(1458019522, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate( "2016-03-15T05:25:22Z" ), "lastHeartbeat" : ISODate( "2016-03-15T05:26:04.822Z" ), "lastHeartbeatRecv" : ISODate( "2016-03-15T05:26:04.821Z" ), "pingMs" : NumberLong(0), "configVersion" : 3 } ], "ok" : 1 } ybb:PRIMARY> |
7.查看复制集的最新配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | ybb:PRIMARY> rs.config();rs.config(); { "_id" : "ybb" , "version" : 3, "protocolVersion" : NumberLong(1), "members" : [ { "_id" : 0, "host" : "cc.example.com:27017" , "arbiterOnly" : false , "buildIndexes" : true , "hidden" : false , "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 1, "host" : "cc.example.com:27018" , "arbiterOnly" : false , "buildIndexes" : true , "hidden" : false , "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 }, { "_id" : 2, "host" : "cc.example.com:27019" , "arbiterOnly" : false , "buildIndexes" : true , "hidden" : false , "priority" : 1, "tags" : { }, "slaveDelay" : NumberLong(0), "votes" : 1 } ], "settings" : { "chainingAllowed" : true , "heartbeatIntervalMillis" : 2000, "heartbeatTimeoutSecs" : 10, "electionTimeoutMillis" : 10000, "getLastErrorModes" : { }, "getLastErrorDefaults" : { "w" : 1, "wtimeout" : 0 } } } ybb:PRIMARY> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)