【Mongodb】 Replica set 的 選舉策略之二
對於Replica Set中的選擇策略:
We use a consensus protocol to pick a primary. Exact details will be spared here but that basic process is:
1 get maxLocalOpOrdinal from each server.
2 if a majority of servers are not up (from this server's POV), remain in Secondary mode and stop.
3 if the last op time seems very old, stop and await human intervention.
4 else, using a consensus protocol, pick the server with the highest maxLocalOpOrdinal as the Primary.
對於策略2:當叢集裡的大多數伺服器發生down 機了,剩餘的節點就會保持在secondary模式並停止服務。
做了實驗結果是對於4節點的 Replica Set,當兩個secondary節點down了的時候,主節點變為secondary。整個叢集相當於掛了,因為secondary 不提供讀寫操作。。
在一個叢集中關閉兩個secondary 節點:rac4:27019和rac3:27017
[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27019
MongoDB shell version: 2.0.1
connecting to: 127.0.0.1:27019/test
SECONDARY>
SECONDARY> use admin
switched to db admin
SECONDARY> db.shutdownServer();
Wed Nov 2 11:02:29 DBClientCursor::init call() failed
Wed Nov 2 11:02:29 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:27019
server should be down...
[mongodb@rac3 bin]$ ./mongo 10.250.7.241:27017
MongoDB shell version: 2.0.1
connecting to: 127.0.0.1:27017/test
SECONDARY>
SECONDARY> use admin
switched to db admin
SECONDARY> db.shutdownServer();
Tue Nov 1 22:02:46 DBClientCursor::init call() failed
Tue Nov 1 22:02:46 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:27017
server should be down...
Tue Nov 1 22:02:46 trying reconnect to 127.0.0.1:27017
Tue Nov 1 22:02:46 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
Tue Nov 1 22:02:46 Error: error doing query: unknown shell/collection.js:150
從主庫的客戶端退出以後,再次進入提示符發生變化:由PRIMARY--->SECONDARY ,檢視Replica Set的狀態資訊:
[mongodb@rac4 bin]$ ./mongo 127.0.0.1:27020
MongoDB shell version: 2.0.1
connecting to: 127.0.0.1:27020/test
SECONDARY>
SECONDARY> rs.status();
{
"set" : "myset",
"date" : ISODate("2011-11-01T13:56:05Z"),
"myState" : 2,
"members" : [
{
"_id" : 0,
"name" : "10.250.7.220:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 101,
"optime" : {
"t" : 1320154033000,
"i" : 1
},
"optimeDate" : ISODate("2011-11-01T13:27:13Z"),
"lastHeartbeat" : ISODate("2011-11-01T13:56:04Z"),
"pingMs" : 0
},
{
"_id" : 1,
"name" : "10.250.7.220:27019",
"health" : 0, --已經關閉
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"t" : 1320154033000,
"i" : 1
},
"optimeDate" : ISODate("2011-11-01T13:27:13Z"),
"lastHeartbeat" : ISODate("2011-11-01T13:53:50Z"),
"pingMs" : 0,
"errmsg" : "socket exception"
},
{
"_id" : 2,
"name" : "10.250.7.220:27020",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY", ---由主庫變為從庫
"optime" : {
"t" : 1320154033000,
"i" : 1
},
"optimeDate" : ISODate("2011-11-01T13:27:13Z"),
"self" : true
},
{
"_id" : 3,
"name" : "10.250.7.241:27017",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"t" : 1320154033000,
"i" : 1
},
"optimeDate" : ISODate("2011-11-01T13:27:13Z"),
"lastHeartbeat" : ISODate("2011-11-01T13:53:54Z"),
"pingMs" : 0,
"errmsg" : "socket exception"
}
],
"ok" : 1
}
SECONDARY> exut
Wed Nov 2 15:23:02 ReferenceError: exut is not defined (shell):1
Wed Nov 2 15:23:02 DBClientCursor::init call() failed
> exit
bye
未完 待續。。。。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-710133/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Mongodb】Replica Set 的選舉策略之三MongoDB
- 【Mongodb】 Replica set 的選舉策略之一MongoDB
- 【Mongodb】如何建立mongodb的replica setMongoDB
- mongodb 3.0 replica set 配置MongoDB
- [MONGODB]: WHEN ARBITER REQUIRED FOR REPLICA SETMongoDBUI
- 【Mongodb】 Replica set 的讀寫分離MongoDB
- 【Mongodb】ReplicaSet的選舉策略之三MongoDB
- MongoDB Replica Set 副本集實踐MongoDB
- MongoDB搭建Replica Set複製集MongoDB
- mongodb replica set 和 nodejs中使用mongoose連線replicaMongoDBNodeJS
- docker 下部署mongodb Replica Set 叢集DockerMongoDB
- mongodb複製集(replica set)搭建及管理MongoDB
- 【MongoDB】高可用方案之副本集(Replica Set)MongoDB
- 【Mongodb】 replica set 新增和刪除節點。MongoDB
- MongoDB副本集replica set (二)--副本集環境搭建MongoDB
- 【Mongodb】 replica set 兩種新增節點方法的日誌分析MongoDB
- MongoDB系列-解決面試中可能遇到的MongoDB複製集(replica set)問題MongoDB面試
- 小丸子學MongoDB系列之——部署Replica Set+Sharded ClusterMongoDB
- MongoDB的選舉過程MongoDB
- mongodb replica sets 測試MongoDB
- mongodb叢集shard_replica的搭建方法MongoDB
- MongoDB 複製集模式Replica SetsMongoDB模式
- Simple Automated Backups for MongoDB Replica SetsMongoDB
- 【Mongodb】 Mongodb sharding 管理之二MongoDB
- MongoDB系列二:Replica Sets安裝與配置MongoDB
- 用通俗易懂的方法解釋MongoDB的選舉機制MongoDB
- Keepalived中Master和Backup角色選舉策略薦AST
- mongodb複製集(replica sets)+分片(sharding)環境搭建MongoDB
- MongoDB 入門教程系列之二:使用 Spring Boot 操作 MongoDBMongoDBSpring Boot
- 演算法--列舉策略演算法
- 利用Mongodb的複製集搭建高可用分片,Replica Sets + Sharding的搭建過程MongoDB
- MongoDB系列三:Replica Sets在生產環境中安裝配置的注意事項MongoDB
- Java列舉的策略設計模式 -DEVJava設計模式dev
- MongoDB最簡單的入門教程之二 使用nodejs訪問MongoDBMongoDBNodeJS
- MongoDB寫入資料策略MongoDB
- 副本集選舉
- MongoDB新的均衡策略和自動合併MongoDB
- MySQL遠端備份策略舉例MySql