mongodb副本集添加节点
1. 准备工作
有一套mongodb 副本集的集群,部署方式参考 mongodb 4.0副本集搭建
准备一个新节点,使用和原副本集版本一致的mongodb
拷贝原副本集中的配置文件、keyfile文件,并注意修改keyfile文件的权限(600)
节点 |
角色 |
192.168.56.199:27017 | PRIMARY |
192.168.56.198:27018 | SECONDARY |
192.168.56.199:27018 | ARBITER |
准备加入的新节点: 192.168.56.197:27017
2. 添加节点
2.1 启动新节点
例如,原节点的版本是4.2.8,新节点版本一致,路径一致,然后启动新节点
/usr/local/mongodb/bin/mongod -f /data/mongodb/27017/etc/mongodb.conf
2.2 主库上查看当前节点及配置信息
使用rs.config()查看配置信息
test12:PRIMARY> rs.config()
{
"_id" : "test12",
"version" : 1,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "192.168.56.198:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "192.168.56.199:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "192.168.56.199:27018",
"arbiterOnly" : true,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : -1,
"catchUpTakeoverDelayMillis" : 30000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("61b86af0a21015e69623e18d")
}
}
rs.status() 查看状态信息
test12:PRIMARY> rs.status()
{
"set" : "test12",
"date" : ISODate("2021-12-14T10:07:46.561Z"),
"myState" : 1,
"term" : NumberLong(1),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"majorityVoteCount" : 2,
"writeMajorityCount" : 2,
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1639476462, 1),
"t" : NumberLong(1)
},
"lastCommittedWallTime" : ISODate("2021-12-14T10:07:42.560Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1639476462, 1),
"t" : NumberLong(1)
},
"readConcernMajorityWallTime" : ISODate("2021-12-14T10:07:42.560Z"),
"appliedOpTime" : {
"ts" : Timestamp(1639476462, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1639476462, 1),
"t" : NumberLong(1)
},
"lastAppliedWallTime" : ISODate("2021-12-14T10:07:42.560Z"),
"lastDurableWallTime" : ISODate("2021-12-14T10:07:42.560Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1639476442, 1),
"lastStableCheckpointTimestamp" : Timestamp(1639476442, 1),
"electionCandidateMetrics" : {
"lastElectionReason" : "electionTimeout",
"lastElectionDate" : ISODate("2021-12-14T09:59:22.407Z"),
"electionTerm" : NumberLong(1),
"lastCommittedOpTimeAtElection" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"lastSeenOpTimeAtElection" : {
"ts" : Timestamp(1639475952, 1),
"t" : NumberLong(-1)
},
"numVotesNeeded" : 2,
"priorityAtElection" : 1,
"electionTimeoutMillis" : NumberLong(10000),
"numCatchUpOps" : NumberLong(0),
"newTermStartDate" : ISODate("2021-12-14T09:59:22.431Z"),
"wMajorityWriteAvailabilityDate" : ISODate("2021-12-14T09:59:23.493Z