標籤:MongoDB 分區架構配置
MongoDB分區架構
前面介紹了MongoDB主從架構和複製集架構的配置,但這兩種配置都有一個共同特性就是只有主節點能讀寫,從節點只能讀。如果主節點寫入的壓力較大,那麼還是會有效能瓶頸。
在Mongodb裡面存在另一種叢集,就是分區技術,可以滿足MongoDB資料量大量增長的需求。當MongoDB儲存海量的資料時,一台機器可能不足以儲存資料,也可能不足以提供可接受的讀寫輸送量。
這時,我們就可以通過在多台機器上分割資料,使得資料庫系統能儲存和處理更多的資料。
展示是MongoDB的分區叢集架構
中主要有如下所述三個主要組件:
Shard: 用於儲存實際的資料區塊,實際生產環境中一個shard server角色可由幾台機器組個一個replica set承擔,防止主機單點故障
Config Server: mongod執行個體,儲存了整個 ClusterMetadata,其中包括 chunk資訊。
Query Routers: 前端路由,用戶端由此接入,且讓整個叢集看上去像單一資料庫,前端應用可以透明使用。
分區叢集配置
建立config複製集:
注意:mongodb3.4版本開始要求config sever是複製集架構,而不能是單台,防止單節點故障
config server的配置, 我這裡是在單機測試機上配置進行測試,dbpath、logpath、port改成不一樣
config server必須設定
configsvr = true
並且設定replSet複製集名稱,前面說了mongodb3.4開始要求config server是複製集架構,不能為單節點
# cat conf1.conf dbpath=/data/mongo/config1configsvr = truelogpath=/var/log/mongo/config/conf1.loglogappend = true fork = trueport = 27100bind_ip=127.0.0.1replSet = conf# cat conf2.conf dbpath=/data/mongo/config2configsvr = truelogpath=/var/log/mongo/config/conf2.loglogappend = true fork = trueport = 27101bind_ip=127.0.0.1replSet = conf
啟動config server兩個執行個體
mongod --config conf1.confmongod --config conf2.conf
config server複製集初始化
> rs.initiate({ _id:"conf",members: [{_id:0, host:"127.0.0.1:27100"},{_id:1, host:"127.0.0.1:27101"}] } ){ "ok" : 1 }conf:PRIMARY> rs.status(){ "set" : "conf", "date" : ISODate("2018-04-20T08:56:14.588Z"), "myState" : 1, "term" : NumberLong(1), "configsvr" : true, "heartbeatIntervalMillis" : NumberLong(2000), "optimes" : { "lastCommittedOpTime" : { "ts" : Timestamp(1524214563, 1), "t" : NumberLong(1) }, "readConcernMajorityOpTime" : { "ts" : Timestamp(1524214563, 1), "t" : NumberLong(1) }, "appliedOpTime" : { "ts" : Timestamp(1524214563, 1), "t" : NumberLong(1) }, "durableOpTime" : { "ts" : Timestamp(1524214563, 1), "t" : NumberLong(1) } }, "members" : [ { "_id" : 0, "name" : "127.0.0.1:27100", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 49, "optime" : { "ts" : Timestamp(1524214563, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2018-04-20T08:56:03Z"), "infoMessage" : "could not find member to sync from", "electionTime" : Timestamp(1524214561, 1), "electionDate" : ISODate("2018-04-20T08:56:01Z"), "configVersion" : 1, "self" : true }, { "_id" : 1, "name" : "127.0.0.1:27101", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 24, "optime" : { "ts" : Timestamp(1524214563, 1), "t" : NumberLong(1) }, "optimeDurable" : { "ts" : Timestamp(1524214563, 1), "t" : NumberLong(1) }, "optimeDate" : ISODate("2018-04-20T08:56:03Z"), "optimeDurableDate" : ISODate("2018-04-20T08:56:03Z"), "lastHeartbeat" : ISODate("2018-04-20T08:56:13.193Z"), "lastHeartbeatRecv" : ISODate("2018-04-20T08:56:13.673Z"), "pingMs" : NumberLong(0), "syncingTo" : "127.0.0.1:27100", "configVersion" : 1 } ], "ok" : 1}
MongoDB 分區架構配置