MongoDB 副本集切換方法
MongoDB 副本集切換方法
1、rs.stepDown([stepdownSecs, catchUpSecs]) step down as primary (disconnects)
操作步驟如下:
[root@127-0-0-1 conf]# mongo --port 2777
shard1:PRIMARY> show dbs
admin 0.000GB
config 0.000GB
local 0.001GB
yoon 0.000GB
shard1:PRIMARY> rs.help()
rs.status() { replSetGetStatus : 1 } checks repl set status
rs.initiate() { replSetInitiate : null } initiates set with default settings
rs.initiate(cfg) { replSetInitiate : cfg } initiates set with configuration cfg
rs.conf() get the current configuration object from local.system.replset
rs.reconfig(cfg) updates the configuration of a running replica set with cfg (disconnects)
rs.add(hostportstr) add a new member to the set with default attributes (disconnects)
rs.add(membercfgobj) add a new member to the set with extra attributes (disconnects)
rs.addArb(hostportstr) add a new member which is arbiterOnly:true (disconnects)
rs.stepDown([stepdownSecs, catchUpSecs]) step down as primary (disconnects)
rs.syncFrom(hostportstr) make a secondary sync from the given member
rs.freeze(secs) make a node ineligible to become primary for the time specified
rs.remove(hostportstr) remove a host from the replica set (disconnects)
rs.slaveOk() allow queries on secondary nodes
rs.printReplicationInfo() check oplog size and time range
rs.printSlaveReplicationInfo() check replica set members and replication lag
db.isMaster() check who is primary
reconfiguration helpers disconnect from the database so the shell will display
an error, even if the command succeeds.
shard1:PRIMARY> rs.stepDown() #這個命令會讓primary降級為Secondary節點
shard1:PRIMARY> rs.stepDown(30) #這個命令會讓primary降級為Secondary節點並維持30S,如果這段時間沒有新的primary選舉出來,這個節點重新加入進行選舉
2、透過設定優先順序
A.為了保證資料的一致性,必須先關閉應用的寫服務
B.提升要升級為primary節點的Secondary節點的優先順序
操作如下:
檢視當前配置資訊:
shard1:PRIMARY> rs.conf()
{
"_id" : "shard1",
"version" : 4,
"protocolVersion" : NumberLong(1),
"writeConcernMajorityJournalDefault" : true,
"members" : [
{
"_id" : 0,
"host" : "127.0.0.1:2777",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 3,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "127.0.0.1:3777",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "127.0.0.1:4777",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"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("5f27de76c8d22581cdeb2f2e")
}
}
shard1:PRIMARY> config=rs.conf() # 檢視當前配置,存入config變數中
shard1:PRIMARY> config.members[2].priority = 3 # 修改config變數,將第三組埠為4777的成員優先順序設定為3
shard1:PRIMARY> rs.reconfig(config) # 配置生效
shard1:PRIMARY> db.isMaster()
{
"hosts" : [
"127.0.0.1:2777",
"127.0.0.1:3777",
"127.0.0.1:4777"
],
"setName" : "shard1",
"setVersion" : 7,
"ismaster" : true,
"secondary" : false,
"primary" : "127.0.0.1:4777",
"me" : "127.0.0.1:4777",
"electionId" : ObjectId("7fffffff0000000000000004"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1596599298, 1),
"t" : NumberLong(4)
},
"lastWriteDate" : ISODate("2020-08-05T03:48:18Z"),
"majorityOpTime" : {
"ts" : Timestamp(1596599298, 1),
"t" : NumberLong(4)
},
"majorityWriteDate" : ISODate("2020-08-05T03:48:18Z")
}..
...
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28939273/viewspace-2709355/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MongoDB日常運維-05副本集故障切換MongoDB運維
- mongodb 4.0副本集搭建MongoDB
- MongoDB 6.0.3副本集搭建MongoDB
- MongoDB日常運維-04副本集搭建MongoDB運維
- MongoDB 4.2副本集新增/刪除副本(一主一副一仲裁)MongoDB
- Mongodb3.0.5副本集搭建及spring和java連線副本集配置MongoDBSpringJava
- MongoDB 4.2副本集自動故障轉移(一主一副一仲裁)MongoDB
- mongodb叢集節點故障的切換方法MongoDB
- mongodb 切換wiredtigerMongoDB
- MongoDB副本集管理方法介紹MongoDB
- MongoDB副本集MongoDB
- 修改mongodb3.0副本集使用者密碼遇到的坑MongoDB密碼
- MongoDB 副本集搭建MongoDB
- MongoDB部署副本集MongoDB
- MongoDB 副本集管理MongoDB
- MongoDB之副本集MongoDB
- 再看MongoDB副本集MongoDB
- 搭建MongoDB副本集MongoDB
- 2.MongoDB 4.2副本集環境基於時間點的恢復MongoDB
- MongoDB - 副本集簡介MongoDB
- MongoDB副本集實踐MongoDB
- 如何配置 MongoDB 副本集MongoDB
- MongoDB副本集replica set (二)--副本集環境搭建MongoDB
- MongoDB 副本集原理及管理MongoDB
- 006.MongoDB副本集MongoDB
- Mongodb資料同步和主從切換MongoDB
- 小丸子學MongoDB系列之——部署MongoDB副本集MongoDB
- MongoDB Replica Set 副本集實踐MongoDB
- mongodb簡單副本集實驗MongoDB
- 使用副本集搭建MongoDB叢集MongoDB
- MongoDB 刪除,新增副本集,並修改副本集IP等資訊MongoDB
- mongodb釋放記憶體-切換日誌MongoDB記憶體
- mongodb副本集新增刪除節點MongoDB
- 手把手教你搭建mongodb副本集MongoDB
- Mongodb分散式叢集副本集+分片MongoDB分散式
- MongoDB 副本集的原理、搭建、應用MongoDB
- MongoDB副本集心跳和同步機制MongoDB
- 在Windows上使用Docker 建立MongoDB 副本集的極簡方法(翻譯)WindowsDockerMongoDB