說明:
在掃盲MongoDB相關的一些知識的時候,順手做下筆記。本文将說明副本集相關的内容。在比較早之前已經對這些有過說明,可以看MongoDB 副本集的原理、搭建、應用。MongoDB中的副本集是一組維護相同資料集的mongod程序,副本集提供備援和高可用性,可提供一定程度的容錯能力,以防止丢失單個資料庫伺服器,是生産部署的基礎。
在某些情況下,複制可以提供更大的讀取容量,因為用戶端可以将讀取操作發送到不同的伺服器。 在不同資料中心中維護資料副本可以提高資料本地性和分布式應用程式的可用性,還可以維護其他副本以用于專用目的,例如災難恢複,報告或備份。
知識點:
一個副本集最多有50個成員,并且最多7個成員有投票權。如果副本集已具有7個投票成員,則其他成員必須是非投票成員,確定副本集的投票成員數為奇數。
副本集的所有成員都可以接受讀取操作。 但預設情況下,應用程式将其讀取操作定向到主要成員。 有關更改預設讀取行為(讀取首選項)請見:Read Preference。如果目前的主要節點不可用,則副本集會進行選擇以選擇哪個輔助節點成為新的主要節點。
副本內建員每2秒鐘彼此發送一次心跳(ping)。 如果心跳未在10秒(
settings.electionTimeoutMillis
)内響應,則其他成員将無法通路的成員标記為無法通路,如果是主節點,則會開始選舉。叢集選擇新的主資料庫之前的中值時間通常不應超過12秒。這包括将主要節點标記為不可用并完成選舉所需的時間。優先級屬性高的從更有可能成為主節點,優先級為0的,則不會參與選舉。
非投票成員的優先級必須為0,優先級大于0的成員必須有投票權。以下狀态的成員才有資格具有投票權:
-
PRIMARY
-
SECONDARY
-
STARTUP2
-
RECOVERING
-
ARBITER
-
ROLLBACK
即具有投票的節點,狀态需要在上面清單中。如一個非投票成員的屬性如:
{
"_id" : <num>,
"host" : <hostname:port>,
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 0,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 0
}
1)Oplog
Oplog(記錄檔)是一個特殊的capped集合,保持所有修改存儲在資料庫中的資料的操作的記錄,類似于MySQL的Binlog,存儲在
local.oplog.rs集合中。
主節點的oplog異步同步到從節點,副本集可以在一個或多個成員失敗的情況下繼續運作。 從資料庫成員将這些操作複制并應用本身。所有副本內建員都将心跳(ping)發送給所有其他成員,任何從成員都可以從任何其他成員應用記錄檔。需要注意的時候,如果副本集隻剩一個節點,該節點會變成從節點(不能寫)。
記錄檔中的每個操作都是幂等的,也就是說oplog操作會産生相同的結果,無論是一次還是多次應用于目标資料集。
OpLog
大小通過參數
oplogSizeMB設定,不設定的話 WiredTiger 存儲引擎預設為空閑磁盤空間5%的大小,上限50G。可以在運作時,手動執行
replSetResizeOplog來改變Oplog的大小。通過
rs.printReplicationInfo()和
db.getReplicationInfo()
來檢視OpLog的狀态:大小、可使用時間等。
從MongoDB 4.2開始,可以限制主資料庫應用Oplog的寫入速率,可以将從延遲保持在
flowControlTargetLagSeconds <
db.adminCommand({ setFeatureCompatibilityVersion: "4.2" }) > 以下。
2)同步過程
初始化同步:複制除local資料庫外的所有資料庫,mongod掃描每個源資料庫中的每個集合,并将所有資料插入這些集合的自己的資料庫中。
在版本3.4中更改:在為每個集合複制文檔時,初始同步将建構所有集合索引(先同步索引,再同步資料)。 在早期版本的MongoDB中,在此階段僅建構_id索引(先同步資料,再同步索引)。
在版本3.4中更改:初始同步在資料複制期間提取新添加的記錄檔記錄。 確定目标成員在local資料庫中具有足夠的磁盤空間,以在此資料複制階段持續時間臨時存儲這些記錄檔記錄。mongod使用源中的記錄檔,将所有更改應用于資料集。初始同步完成後,成員将從STARTUP2轉換為SECONDARY。
初始化時,同步源的選擇取決于mongod啟動參數
initialSyncSourceReadPreference
的值(4.2.7中的新增功能)。如果無法選擇同步源,将記錄錯誤并等待1秒鐘,然後重新選擇,從mongod最多可以重新初始同步源選擇過程10次,然後錯誤退出。選擇同步源的要求可以看這裡。
3)複制:多線程
MongoDB使用多線程批量應用寫入操作以提高并發性。 MongoDB按文檔ID(WiredTiger)對批次進行分組,并同時使用不同的線程來應用每組操作,MongoDB始終以原始寫入順序對給定文檔應用寫入操作。
4)成員
① Primary:處理所有寫操作。
② Secondaries:從主資料庫(oplog)複制操作,并将操作應用于其資料集,以維護相同的資料集,其有各種屬性:優先級、延遲、隐藏等。
③ Arbiter:仲裁節點,隻投票,不儲存資料,節省存儲成本。從MongoDB 3.6開始,仲裁程式的優先級隻能為0。因為不存儲資料,是以不具有用于身份驗證的使用者和角色映射的内部表。在認證的情況下登入的唯一方法是使用localhost。
成員屬性
① 優先級屬性(Priority):優先級為0的成員不能成為Primary,并且不能觸發選舉,但能選舉投票和讀取。
② 隐藏屬性(Hidden):優先級為0,有投票權。适用于具有與副本集中其他成員不同的使用模式的工作負載(備份<
db.fsyncLock()
>、報表)。mongos不會與隐藏成員互動。
③ 延遲屬性(Delayed):用于恢複,必須是優先級為0的成員,有隐藏屬性,可以有投票權。對于分片中的平衡作用有限。延遲機關為秒:
cfg = rs.conf()
cfg.members[0].priority = 0
cfg.members[0].hidden = true
cfg.members[0].slaveDelay = 3600
rs.reconfig(cfg)
④ 投票(votes):投票權為0的成員不能确定"majority" write concern。
⑤ 标簽(tags):通過标簽,可以設定readpreference、readConcern和writeConcern。
成員狀态
狀态值 狀态名 狀态說明
0 STARTUP 所有成員都以該狀态啟動,mongod在啟動狀态下解析副本集配置文檔。
1 PRIMARY 主節點狀态,唯一支援寫的節點。有投票資格
2 SECONDARY 從節點狀态,複制同步資料。有投票資格
3 RECOVERING 恢複狀态,要麼從完成復原或重新同步過渡。有投票資格
5 STARTUP2 加入副本集,并正在運作初始同步。有投票資格
6 UNKNOWN 從副本集的另一個成員的角度來看,該成員的狀态尚不清楚。沒有投票資格
7 ARBITER 仲裁節點狀态,不複制資料,僅存在于參加選舉中。 有投票資格
8 DOWN 從副本集的另一個成員的角度來看,該成員不可通路。沒有投票資格
9 ROLLBACK 復原節點狀态,無法從該成員讀取資料。有投票資格
10 REMOVED 删除節點狀态,從副本集中删除。
部署:
環境:版本(4.2.8)
192.168.163.134:27017
192.168.163.134:27018
192.168.163.134:27019
配置檔案:其中一個節點的配置

systemLog:
verbosity: 0
quiet: false
traceAllExceptions: false
path: "/usr/local/mongodb_1/logs/mongodb.log"
logAppend: true
logRotate: rename
destination: file
timeStampFormat: iso8601-local
processManagement:
fork: true
pidFilePath: "/usr/local/mongodb_1/mongodb.pid"
net:
port: 27017
bindIp: 0.0.0.0
maxIncomingConnections: 65536
wireObjectCheck: true
unixDomainSocket:
enabled: true
pathPrefix: /tmp
filePermissions: 0700
security:
# keyFile: "/usr/local/mongodb_1/test-keyfile"
authorization: disabled
storage:
dbPath: "/usr/local/mongodb_1/data"
journal:
enabled: true
commitIntervalMs: 500
directoryPerDB: true
syncPeriodSecs: 60
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 1
journalCompressor: snappy
directoryForIndexes: false
maxCacheOverflowFileSizeGB: 0
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true
operationProfiling:
# 指定應分析哪些操作,預設off:分析器已關閉,并且不收集任何資料;slowOp:收集比slowms的時間長的資料;all:收集所有操作的資料
mode: slowOp
# 慢操作時間門檻值(以毫秒為機關),版本4.0中進行了更改:slowOpThresholdMs設定可用于mongod和mongos
slowOpThresholdMs: 100
# 分析記錄慢速操作
slowOpSampleRate: 1.0
# 過濾器,記錄耗時超過2秒的查詢操作
#filter: '{ op: "query", millis: { $gt: 2000 } }'
replication:
oplogSizeMB: 100
replSetName: shard1
enableMajorityReadConcern: false
sharding:
clusterRole: shardsvr
archiveMovedChunks: false
# mongos配置項,指定配置伺服器
#configDB: <configReplSetName>/cfg1.example.net:27019, cfg2.example.net:27019,...
View Code
按照配置檔案裡的配置,建立好各個目錄。
啟動節點:3個節點
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb_1/mongo.conf
搭建:
①:無認證搭建(authorization: disabled)
> rs.initiate(
{
_id : 'shard1',
members: [
{ _id : 0, host : "192.168.163.134:27017" },
{ _id : 1, host : "192.168.163.134:27018" },
{ _id : 2, host : "192.168.163.134:27019" }
]
}
)
說明:副本集為shard1,3個成員(PSS)
"_id": 副本集的名稱
"members": 副本集的伺服器清單
"_id": 成員的ID
"host": 成員的位址和端口
-- 以上是必填的,下面的成員屬性按照需要設定:
"priority": 是優先級,預設為1,優先級0為被動節點,不能成為活躍節點。優先級不為0則按照有大到小選出活躍節點。
"arbiterOnly": 仲裁節點,隻參與投票,不接收資料,也不能成為活躍節點。
"hidden": 隐藏節點,優先級和投票必須為0。
"votes": 投票資格,0為沒有投票資格;1為有投票資格。
"slaveDelay": 延遲節點,機關為秒。
"tags": 标簽屬性。
可以通過日志看到副本集初始化的一些具體資訊:

2021-02-24T07:54:29.381+0000 I REPL [initandlisten] Did not find local initialized voted for document at startup.
2021-02-24T07:54:29.381+0000 I REPL [initandlisten] Did not find local Rollback ID document at startup. Creating one.
2021-02-24T07:54:29.423+0000 I REPL [initandlisten] Initialized the rollback ID to 1
2021-02-24T07:54:29.423+0000 I REPL [initandlisten] Did not find local replica set configuration document at startup; NoMatchingDocument: Did not find replica set configuration document in local.system.replset
2021-02-24T07:55:57.511+0000 I REPL [conn2] replSetInitiate admin command received from client
2021-02-24T07:55:57.517+0000 I REPL [conn2] replSetInitiate config object with 3 members parses ok
2021-02-24T07:55:57.517+0000 I REPL [conn2] Scheduling remote command request for initiate quorum check: RemoteCommand 1 -- target:192.168.163.134:27018 db:admin cmd:{ replSetHeartbeat: "shard1", checkEmpty: true, configVersion: 1, hbv: 1, from: "192.168.163.134:27017", fromId: 0, term: 0 }
2021-02-24T07:55:57.517+0000 I REPL [conn2] Scheduling remote command request for initiate quorum check: RemoteCommand 2 -- target:192.168.163.134:27019 db:admin cmd:{ replSetHeartbeat: "shard1", checkEmpty: true, configVersion: 1, hbv: 1, from: "192.168.163.134:27017", fromId: 0, term: 0 }
2021-02-24T07:55:57.521+0000 I REPL [conn2] ******
2021-02-24T07:55:57.522+0000 I REPL [conn2] creating replication oplog of size: 100MB...
2021-02-24T07:55:57.582+0000 I REPL [conn2] ******
2021-02-24T07:55:57.674+0000 I REPL [conn2] New replica set config in use: { _id: "shard1", version: 1, protocolVersion: 1, writeConcernMajorityJournalDefault: true, members: [ { _id: 0, host: "192.168.163.134:27017", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 1, host: "192.168.163.134:27018", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 2, host: "192.168.163.134:27019", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 } ], settings: { chainingAllowed: true, heartbeatIntervalMillis: 2000, heartbeatTimeoutSecs: 10, electionTimeoutMillis: 10000, catchUpTimeoutMillis: -1, catchUpTakeoverDelayMillis: 30000, getLastErrorModes: {}, getLastErrorDefaults: { w: 1, wtimeout: 0 }, replicaSetId: ObjectId('6036068d6eda8e54419e12a1') } }
2021-02-24T07:55:57.675+0000 I REPL [conn2] This node is 192.168.163.134:27017 in the config
2021-02-24T07:55:57.675+0000 I REPL [conn2] transition to STARTUP2 from STARTUP
2021-02-24T07:55:57.676+0000 I REPL [replexec-0] Member 192.168.163.134:27018 is now in state STARTUP
2021-02-24T07:55:57.676+0000 I REPL [replexec-0] Member 192.168.163.134:27019 is now in state STARTUP
2021-02-24T07:55:57.676+0000 I REPL [conn2] Starting replication storage threads
2021-02-24T07:55:57.678+0000 I REPL [conn2] transition to RECOVERING from STARTUP2
2021-02-24T07:55:57.678+0000 I REPL [conn2] Starting replication fetcher thread
2021-02-24T07:55:57.678+0000 I REPL [conn2] Starting replication applier thread
2021-02-24T07:55:57.678+0000 I REPL [conn2] Starting replication reporter thread
2021-02-24T07:55:57.680+0000 I REPL [rsSync-0] Starting oplog application
2021-02-24T07:55:57.711+0000 I REPL [rsSync-0] transition to SECONDARY from RECOVERING
2021-02-24T07:55:57.711+0000 I REPL [rsSync-0] Resetting sync source to empty, which was :27017
2021-02-24T07:55:57.711+0000 I REPL [rsBackgroundSync] waiting for 2 pings from other members before syncing
2021-02-24T07:55:58.177+0000 I REPL [replexec-1] Member 192.168.163.134:27018 is now in state STARTUP2
2021-02-24T07:55:58.177+0000 I REPL [replexec-1] Member 192.168.163.134:27019 is now in state STARTUP2
2021-02-24T07:55:59.681+0000 I REPL [replexec-0] Member 192.168.163.134:27018 is now in state SECONDARY
2021-02-24T07:55:59.681+0000 I REPL [replexec-0] Member 192.168.163.134:27019 is now in state SECONDARY
2021-02-24T07:56:07.922+0000 I REPL [replexec-0] Scheduling remote command request for vote request: RemoteCommand 45 -- target:192.168.163.134:27018 db:admin cmd:{ replSetRequestVotes: 1, setName: "shard1", dryRun: true, term: 0, candidateIndex: 0, configVersion: 1, lastCommittedOp: { ts: Timestamp(1614153357, 1), t: -1 } }
2021-02-24T07:56:07.922+0000 I REPL [replexec-0] Scheduling remote command request for vote request: RemoteCommand 46 -- target:192.168.163.134:27019 db:admin cmd:{ replSetRequestVotes: 1, setName: "shard1", dryRun: true, term: 0, candidateIndex: 0, configVersion: 1, lastCommittedOp: { ts: Timestamp(1614153357, 1), t: -1 } }
2021-02-24T07:56:07.926+0000 I REPL [replexec-1] Scheduling remote command request for vote request: RemoteCommand 47 -- target:192.168.163.134:27018 db:admin cmd:{ replSetRequestVotes: 1, setName: "shard1", dryRun: false, term: 1, candidateIndex: 0, configVersion: 1, lastCommittedOp: { ts: Timestamp(1614153357, 1), t: -1 } }
2021-02-24T07:56:07.928+0000 I REPL [replexec-1] Scheduling remote command request for vote request: RemoteCommand 48 -- target:192.168.163.134:27019 db:admin cmd:{ replSetRequestVotes: 1, setName: "shard1", dryRun: false, term: 1, candidateIndex: 0, configVersion: 1, lastCommittedOp: { ts: Timestamp(1614153357, 1), t: -1 } }
2021-02-24T07:56:07.929+0000 I REPL [replexec-0] transition to PRIMARY from SECONDARY
2021-02-24T07:56:07.929+0000 I REPL [replexec-0] Resetting sync source to empty, which was :27017
2021-02-24T07:56:07.930+0000 I REPL [replexec-0] Entering primary catch-up mode.
2021-02-24T07:56:07.931+0000 I REPL [replexec-0] Caught up to the latest optime known via heartbeats after becoming primary. Target optime: { ts: Timestamp(1614153357, 1), t: -1 }. My Last Applied: { ts: Timestamp(1614153357, 1), t: -1 }
2021-02-24T07:56:07.931+0000 I REPL [replexec-0] Exited primary catch-up mode.
2021-02-24T07:56:07.931+0000 I REPL [replexec-0] Stopping replication producer
2021-02-24T07:56:07.931+0000 I REPL [ReplBatcher] Oplog buffer has been drained in term 1
2021-02-24T07:56:07.932+0000 I REPL [ReplBatcher] Oplog buffer has been drained in term 1
2021-02-24T07:56:07.932+0000 I REPL [RstlKillOpThread] Starting to kill user operations
2021-02-24T07:56:07.932+0000 I REPL [RstlKillOpThread] Stopped killing user operations
2021-02-24T07:56:07.932+0000 I REPL [RstlKillOpThread] State transition ops metrics: { lastStateTransition: "stepUp", userOpsKilled: 0, userOpsRunning: 0 }
2021-02-24T07:56:07.983+0000 I REPL [rsSync-0] transition to primary complete; database writes are now permitted
大緻的流程是:檢查配置、初始化local庫的各個集合、轉換各個成員的狀态(STARTUP -> STARTUP2 -> RECOVERING -> SECONDARY)、10秒後開始選舉(SECONDARY -> PRIMARY)
TIP:
可以把副本集的配置先聲明好,再用
replSetInitiate進行初始化(PSA):
> cfg = {
_id : 'shard1',
members: [
{ _id : 0, host : "192.168.163.134:27017" },
{ _id : 1, host : "192.168.163.134:27018" },
{ _id : 2, host : "192.168.163.134:27019", arbiterOnly: true }
]
}
> db.runCommand({ replSetInitiate : cfg })
或則
> rs.initiate(cfg)
②:有認證搭建(authorization: true)
從安全上考慮,需要為執行個體添加使用者來進行通路控制。在添加了認證的執行個體上,副本集各個成員之間的通路就需要認證,現在來說明通過Keyfile的方式進行成員間的認證。
1. 建立keyfile:使用YAML格式,長度為6~1024字元,并且隻能包含base64集中的字元
使用keyfile進行身份驗證,副本集中的每個mongod執行個體都将keyfile的内容用作共享密碼來進行身份驗證。生成方法:
openssl rand -base64 756 > xx_keyfile
chmod 400 xx_keyfile --Linux需要
2. 生成好keyfile之後,副本集中的所有成員都共享該檔案,複制到各個執行個體的目錄,并修改配置檔案參數:開啟了keyFile參數之後,認證自動啟動(authorization)。
security:
keyFile: "/usr/local/mongodb_1/xx_keyfile"
authorization: enabled
3. 開啟執行個體,并進行部署:
-- 啟動3個節點
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb_1/mongo.conf
-- 初始化副本集
> rs.initiate(
{
_id : 'shard1',
members: [
{ _id : 0, host : "192.168.163.134:27017" },
{ _id : 1, host : "192.168.163.134:27018" },
{ _id : 2, host : "192.168.163.134:27019" }
]
}
)
-- 建立管理使用者
> db.createUser(
{
user:'dba',
pwd:passwordPrompt(),
roles:[{role:'root',db:'admin'}],
customData:{name:'運維賬号'}
}
)
注意:當認證開啟之後,第一次必須建立管理使用者,後續的登入需要認證才能操作。到此,副本集部署已經完成,部署比較簡單,更多的部署資訊可以看官方文檔說明。
副本集維護
維護方面的包括很多:擴容、縮容、修改屬性、副本集指令行等等,本節開始對日常工作中遇到的一些操作進行說明,關于副本集的一些指令說明可以看文檔。
1. 擴容
新增節點:rs.add(host, arbiterOnly):參數為字元串或則文檔,arbiterOnly可選,在host為字元串的時候使用。
字元串的格式為:主機名(IP)和端口:
IP:Port
文檔的格式為:
{
_id: <int>,
host: <string>,
arbiterOnly: <boolean>,
buildIndexes: <boolean>,
hidden: <boolean>,
priority: <number>,
tags: <document>,
slaveDelay: <int>,
votes: <number>
}
① 用主機參數添加:該方式添加的成員屬性是預設的。
> rs.add("192.168.163.134:27019")
② 用文檔參數添加:該方式添加的成員屬性可以自定義。如添加一個優先級為0的隐藏節點:
> rs.add({"_id":3,"host":"192.168.163.134:27019","priority":0,"hidden":true})
此外,還可以添加其他屬性的成員,比如:延遲、投票、标簽、仲裁等等。
除了用rs.add添加之外,還可以用
replSetReconfig(rs.reconfig)來修改配置進行添加,其中仲裁節點可以用rs.addArb來進行快速添加。
③ 添加仲裁節點:
rs.
addArb
(host):
> rs.addArb('192.168.163.134:27019')
2. 縮容
移除節點:rs.remove(hostname):參數為字元串
IP:Port
從叢集中移除剛添加的隐藏節點:
> rs.remove("192.168.163.134:27019")
除了用rs.remove移除之外,還可以用
replSetReconfig(rs.reconfig)來修改配置進行移除。需要注意的運作rs.remove之前,最好關閉要删除的副本內建員。
預設情況下,副本內建員需要等待5分鐘,然後再斷開與已删除成員的連接配接,4.2之後可以在其餘其他成員上執行以下指令來關閉連接配接:
db.adminCommand(
{
"dropConnections" : 1,
"hostAndPort" : [
"192.168.163.134:27019"
]
}
)
3. 修改成員屬性:
rs.
reconfig
(configuration, force):參數為配置文檔,force:強制副本集接受新配置,即使大多數成員不可通路,允許向非主節點發出重新配置指令:rs.reconfig(cfg,{force:true}) 。重新配置現有副本集,覆寫現有的配置,預設必須連接配接到副本集的主資料庫。在某些情況下,rs.reconfig可以觸發目前主資料庫降級,通過該方法實作的主庫降級,新選出來的主大概需要花費10~12秒,後面有自動降級的方法可以減少選主時間。
4.2開始,當主資料庫降級時,不再關閉所有用戶端連接配接,并且正在進行的寫入将被殺死。
4.0和更早版本中,當主資料庫降級時,它将關閉所有用戶端連接配接。
通指定某一個成員為主,修改其優先級為所有成員中最大:
① 擷取副本集配置文檔
> cfg = rs.conf()
② 修改文檔中指定成員的屬性:優先級
> cfg.members[1].priority = 2
③ 新文檔生效
> rs.reconfig(cfg)
大概10~12秒左右,會完成新主的選舉。也可以主動降級來加快新主的選擇,用rs.stepDown。
4. 主節點降級為備份節點:
rs.
stepDown
(stepDownSecs, secondaryCatchUpPeriodSecs)
該方法不會立即降級主庫, 如果沒有可選舉的從節點,則主節點将等待secondaryCatchUpPeriodSecs(預設為10秒),以等待從節點趕上。 一旦可以選擇的從節點可用,就降級主節點。降級後,原始的主節點将成為從節點,并且在stepDownSecs指定的剩餘時間内沒有資格再次成為主節點,預設60秒。
4.2開始,rs.stepDown方法不再關閉所有用戶端連接配接
4.0和更早版本中,rs.stepDown方法在降級期間關閉所有用戶端連接配接
和3中的步驟一樣,可以先修改優先級屬性,再在主節點上執行:
> rs.stepDown(60,10)
注意:rs.stepDown開始的時間段内,所有對主的寫入都會失敗,直到選擇了新的主資料庫,或者如果沒有可選舉的輔助資料庫,則原始主資料庫将恢複正常操作。正在進行的寫入将被殺死,正在進行的事務也會因“ TransientTransactionError”而失敗,并且可以整體重試。寫入失敗的時間最多為20秒:
secondaryCatchUpPeriodSecs(預設為10秒)+選舉逾時Millis(預設為10秒)
5. 讓從節點在一定時間内不能成為主節點:
rs.
freeze
(seconds)
始終出于備份節點狀态,強制他們出于從節點狀态。比如在需要對副本集的各個節點進行輪詢的維護,在優先級高的節點上執行了降級之後,雖然暫時成為了從節點,但在下個選舉周期還是會被選舉成為主節點,如果維護的時間比較長,可以在降級之後再執行,讓他完成維護操作為止。
> rs.freeze(3600)
如果修改完操作之後,需要恢複,則可以直接用0來執行,不阻止更新為主節點:
> rs.freeze(0)
6. 修改同步源:
rs.
syncFrom
(hostname):參數為IP:Port
修改目前成員的預設同步目标。 以[主機名]:[端口]的形式指定要複制的成員的名稱。從版本3.2中開始:具有投票權(>0)的副本內建員不能與沒有投票權(0)的成員同步。
配置好的副本集都是自動的對同步源進行配置設定,根據pingMS來尋找最新的資料源,可能某個Secondary是另一個Secondary的同步源。如果目前主節點(PSS)的壓力比較大,可以修改從節點的同步目标,修改到另一個成員,組成一個鍊級的複制(P -> S -> S),減輕主節點的壓力,但可能會出現複制延遲不可控的情況。
① 檢視同步源
shard1:SECONDARY> db.adminCommand({"replSetGetStatus":1}).syncingTo
192.168.163.134:27018
shard1:SECONDARY> rs.status().syncingTo
192.168.163.134:27018
② 修改同步源
shard1:SECONDARY> rs.syncFrom("192.168.163.134:27017")
{
"syncFromRequested" : "192.168.163.134:27017",
"prevSyncTarget" : "192.168.163.134:27018",
"ok" : 1
}
> db.adminCommand({"replSetSyncFrom":"192.168.163.134:27017"})
{
"syncFromRequested" : "192.168.163.134:27017",
"prevSyncTarget" : "192.168.163.134:27018",
"ok" : 1
}
7. 檢視主從節點的延遲和OpLog資訊:
rs.
printReplicationInfo
(),
rs.
printSlaveReplicationInfo
()
shard1:PRIMARY> rs.printSlaveReplicationInfo()
source: 192.168.163.134:27017 --從節1點的落後時間
syncedTo: Thu Feb 25 2021 09:27:05 GMT+0000 (UTC)
0 secs (0 hrs) behind the primary
source: 192.168.163.134:27019 --從節點2的落後時間
syncedTo: Thu Feb 25 2021 09:27:05 GMT+0000 (UTC)
0 secs (0 hrs) behind the primary
shard1:PRIMARY> rs.printReplicationInfo()
configured oplog size: 100MB --oplog大小
log length start to end: 25707secs (7.14hrs) --oplog使用的時間長度
oplog first event time: Thu Feb 25 2021 02:18:28 GMT+0000 (UTC) -- 第一次操作時間
oplog last event time: Thu Feb 25 2021 09:26:55 GMT+0000 (UTC) -- 最後一次操作時間
now: Thu Feb 25 2021 09:26:59 GMT+0000 (UTC) --目前時間
以上的幾種方法是日常維護副本集會用到的,還有其他的比如:
db.serverStatus() == db.runCommand( { serverStatus: 1 } )
可帶參數:db.serverStatus( { repl: 0, metrics: 0, locks: 0 } )、db.runCommand( { serverStatus: 1, repl: 0, metrics: 0, locks: 0 } )

XYZ:PRIMARY> db.runCommand( { serverStatus: 1 } )
{
"host" : "lbs-postgresql01", -- 主機名
"version" : "4.2.8", -- 版本
"process" : "mongod", -- 程序名,可能的值為:mongos或mongod
"pid" : NumberLong(27568), -- pid
"uptime" : 30149, -- 服務運作時間(秒)
"uptimeMillis" : NumberLong(30149594), -- 服務運作時間(毫秒)
"uptimeEstimate" : NumberLong(30149), -- 服務運作時間(秒),根據MongoDB内部處理統計
"localTime" : ISODate("2020-08-13T09:20:24.614Z"), -- 根據伺服器,以UTC表示目前時間的ISODate
"asserts" : { -- 報告自MongoDB流程啟動以來提出的斷言數量的文檔。雖然斷言錯誤通常很少見,但是如果斷言的值不為零,則應檢查日志檔案以擷取更多資訊。
"regular" : 0, -- 自MongoDB流程開始以來提出的正常聲明的數量。檢查日志檔案以擷取有關這些消息的更多資訊。
"warning" : 0, -- 該字段傳回自MongoDB程序啟動以來引發的警告數,從MongoDB 4.0開始,該字段傳回零0
"msg" : 0, -- 自MongoDB程序啟動以來引發的消息聲明的數量。檢查日志檔案以擷取有關這些消息的更多資訊。
"user" : 2244, -- 自上次啟動MongoDB程序以來發生的“使用者斷言”數量。 如磁盤空間不足或重複密鑰。
"rollovers" : 0 -- 自上次MongoDB程序啟動以來,翻轉計數器已翻轉的次數。 230個斷言後,計數器将翻轉為零。
},
"connections" : { -- 報告連接配接狀态的文檔。使用這些值可以評估伺服器的目前負載和容量要求。
"current" : 11, -- 目前連接配接數
"available" : 52417, -- 可用連接配接數
"totalCreated" : 38, -- 總建立的連接配接數
"active" : 2 -- 活躍連接配接數
},
"electionMetrics" : { -- 選舉資訊
"stepUpCmd" : { -- Primary down時,在選舉交接中調用的選舉名額
"called" : NumberLong(0),
"successful" : NumberLong(0)
},
"priorityTakeover" : { -- 由mongod執行個體調用的選舉名額,因為其優先級高于Primary
"called" : NumberLong(0),
"successful" : NumberLong(0)
},
"catchUpTakeover" : { -- 由mongod執行個體調用的選舉名額,因為其資料比Primary新
"called" : NumberLong(0),
"successful" : NumberLong(0)
},
"electionTimeout" : { -- 由mongod執行個體調用的選舉名額,因為其無法在settings.electionTimeoutMillis内到達Primary
"called" : NumberLong(1),
"successful" : NumberLong(1)
},
"freezeTimeout" : { -- mongod執行個體在當機期(成員無法申請選舉)之後調用的選舉名額
"called" : NumberLong(0),
"successful" : NumberLong(0)
},
"numStepDownsCausedByHigherTerm" : NumberLong(0), -- 由于更高的任期(term),該mongod執行個體down的次數
"numCatchUps" : NumberLong(0), -- 作為新當選的主必須趕上已知的最高oplog條目的選舉次數
"numCatchUpsSucceeded" : NumberLong(0), -- 作為新當選的主成功追上已知的最高oplog條目的次數
"numCatchUpsAlreadyCaughtUp" : NumberLong(1), -- 作為新當選的主完成追趕的次數,因為當選時已經被追趕
"numCatchUpsSkipped" : NumberLong(0), -- 作為新當選的主跳過追趕過程的次數
"numCatchUpsTimedOut" : NumberLong(0), -- 由于settings.catchUpTimeoutMillis限制,作為新當選的主完成其追趕過程的次數
"numCatchUpsFailedWithError" : NumberLong(0), -- 新當選的主追趕過程因錯誤而失敗的次數
"numCatchUpsFailedWithNewTerm" : NumberLong(0), -- 由于另一位成員的任期較高(即其他一位或多位議員參加了其他選舉),新當選的主追趕過程結束的次數
"numCatchUpsFailedWithReplSetAbortPrimaryCatchUpCmd" : NumberLong(0), -- 由于收到replSetAbortPrimaryCatchUp指令而導緻的新當選的主追趕過程結束的次數
"averageCatchUpOps" : 0 -- 新當選的主在趕超過程中平均執行的操作數
},
"extra_info" : { -- 提供有關基礎系統的其他資訊的文檔
"note" : "fields vary by platform", -- 文本為“字段因平台而異”的字元串
"user_time_us" : NumberLong(114316152), -- 使用者使用的CPU時間
"system_time_us" : NumberLong(19584160), -- 核心使用的CPU時間
"maximum_resident_set_kb" : NumberLong(91260), -- 執行程式所占用記憶體的最大值。機關是 KB
"input_blocks" : NumberLong(0), -- 輸入塊
"output_blocks" : NumberLong(263944), -- 輸出塊
"page_reclaims" : NumberLong(97588), -- 頁回收數量
"page_faults" : NumberLong(0), -- 數量錯誤數量
"voluntary_context_switches" : NumberLong(1497531), -- 主動上下文切換數量
"involuntary_context_switches" : NumberLong(3283) -- 被動上下文切換數量
},
"flowControl" : { -- 使用流量控制時最大滞後時間。将嘗試将大多數的延遲保持在指定的秒數内(10秒)https://docs.mongodb.com/v4.2/reference/parameters/#param.enableFlowControl
"enabled" : true, -- 是否開啟,https://docs.mongodb.com/v4.2/reference/parameters/#param.enableFlowControl
"targetRateLimit" : 1000000000, -- 主伺服器上運作時,每秒可以擷取的最大票證數量;輔助伺服器上運作時,傳回的數字是占位符
"timeAcquiringMicros" : NumberLong(780), -- 主資料庫上運作時,寫操作等待擷取票證的總時間;輔助伺服器上運作時,傳回的數字是占位符
"locksPerOp" : 1.167, -- 主伺服器上運作時,近似于每個操作擷取的鎖數;輔助伺服器上運作時,傳回的數字是占位符
"sustainerRate" : 0, -- 主伺服器上運作時,輔助伺服器每秒維持送出點的每秒近似操作數;輔助伺服器上運作時,傳回的數字是占位符
"isLagged" : false, -- 主資料庫上運作時,是否已使用流控制。 當大多數承諾滞後時間大于已配置的flowControlTargetLagSeconds的某個百分比時,将啟用流控制
"isLaggedCount" : 0, -- 主伺服器上運作時,自上次重新啟動以來流控制已參與的次數;輔助伺服器上運作時,傳回的數字是占位符
"isLaggedTimeMicros" : NumberLong(0) -- 主伺服器上運作時,自上次重新啟動以來已花費了多少時間進行流控制
},
"freeMonitoring" : { -- 是否開啟雲監控
"state" : "undecided"
},
"globalLock" : { -- 報告資料庫鎖定狀态的文檔,
"totalTime" : NumberLong("30149591000"), -- 自資料庫啟動并建立globalLock以來的時間(以微秒為機關)。這大緻相當于伺服器的總正常運作時間。
"currentQueue" : { -- 由于鎖而排隊的操作數的資訊的文檔
"total" : 0, -- 排隊等待鎖定的操作總數(即globalLock.currentQueue.readers和globalLock.currentQueue.writers的總和)
"readers" : 0, -- 目前排隊并等待讀鎖定的操作數。始終較小的讀取隊列,尤其是較短的操作,不會引起任何問題。
"writers" : 0 -- 目前排隊并等待寫鎖定的操作數。始終較小的寫隊列,尤其是較短操作的寫隊列,無需擔心。
},
"activeClients" : { -- 提供有關已連接配接用戶端數量以及這些用戶端執行的讀取和寫入操作的資訊的文檔。
"total" : 0, -- 與資料庫的内部用戶端連接配接總數,包括系統線程以及排隊的讀取器和寫入器。
"readers" : 0, -- 執行讀取操作的活動用戶端連接配接數。
"writers" : 0 -- 執行寫操作的活動用戶端連接配接數。
}
},
"locks" : { -- 針對每個鎖<類型>報告有關鎖<模式>的資料的文檔。https://docs.mongodb.com/v4.2/reference/command/serverStatus/#locks
"ParallelBatchWriterMode" : { -- 并行批處理寫入器模式的鎖
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"r" : NumberLong(32460) -- 意向讀鎖(IS)
}
},
"ReplicationStateTransition" : { -- 副本內建員狀态轉換的鎖定
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"w" : NumberLong(209603), -- 意向寫鎖(IX)
"W" : NumberLong(2) -- 排他(X)鎖
},
"acquireWaitCount" : { -- 由于鎖處于沖突模式而導緻的locks.acquireCount鎖擷取遇到的等待次數。
"w" : NumberLong(2), -- 意向寫鎖(IX)
"W" : NumberLong(1) -- 排他(X)鎖
},
"timeAcquiringMicros" : { -- 鎖定擷取的累積等待時間(以微秒為機關)
"w" : NumberLong(175), -- 意向寫鎖(IX)
"W" : NumberLong(2) -- 排他(X)鎖
}
},
"Global" : { -- 全局鎖
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"r" : NumberLong(206263), -- 意向讀鎖(IS)
"w" : NumberLong(3335), -- 意向寫鎖(IX)
"W" : NumberLong(5) -- 排他(X)鎖
},
"acquireWaitCount" : { -- 由于鎖處于沖突模式而導緻的locks.acquireCount鎖擷取遇到的等待次數。
"w" : NumberLong(1), -- 意向寫鎖(IX)
"W" : NumberLong(1) -- 排他(X)鎖
},
"timeAcquiringMicros" : { -- 鎖定擷取的累積等待時間(以微秒為機關)
"w" : NumberLong(11524), -- 意向寫鎖(IX)
"W" : NumberLong(36) -- 排他(X)鎖
}
},
"Database" : { -- 資料庫鎖
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"r" : NumberLong(145945), -- 意向讀鎖(IS)
"w" : NumberLong(496), -- 意向寫鎖(IX)
"W" : NumberLong(27) -- 排他(X)鎖
},
"acquireWaitCount" : { -- 由于鎖處于沖突模式而導緻的locks.acquireCount鎖擷取遇到的等待次數。
"r" : NumberLong(2) -- 意向讀鎖(IS)
},
"timeAcquiringMicros" : { -- 鎖定擷取的累積等待時間(以微秒為機關)
"r" : NumberLong(10074) -- 意向讀鎖(IS)
}
},
"Collection" : { -- 集合鎖
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"r" : NumberLong(34475), -- 意向讀鎖(IS)
"w" : NumberLong(494), -- 意向寫鎖(IX)
"R" : NumberLong(1), -- 共享(S)鎖
"W" : NumberLong(18) -- 排他(X)鎖
}
},
"Metadata" : { -- 中繼資料鎖
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"W" : NumberLong(1) -- 排他(X)鎖
}
},
"Mutex" : { -- 互斥鎖
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"r" : NumberLong(126997) -- 意向(IS)
}
},
"oplog" : { -- oplog鎖
"acquireCount" : { -- 在指定模式下擷取鎖定的次數
"r" : NumberLong(115593), -- 意向讀鎖(IS)
"w" : NumberLong(2), -- 共享(S)鎖
"W" : NumberLong(1) -- 排他(X)鎖
}
}
},
"logicalSessionRecordCache" : { -- 提供有關伺服器會話緩存的名額
"activeSessionsCount" : 1, -- 自上次重新整理周期以來,由mongod或mongos執行個體緩存在記憶體中所有活動的本地會話數。
"sessionsCollectionJobCount" : 101, -- 跟蹤重新整理過程在config.system.sessions集合上運作的次數的數字。
"lastSessionsCollectionJobDurationMillis" : 4, -- 上次重新整理的時間(以毫秒為機關)
"lastSessionsCollectionJobTimestamp" : ISODate("2020-08-13T09:17:55.863Z"), -- 上次重新整理發生的時間
"lastSessionsCollectionJobEntriesRefreshed" : 1, -- 在上次重新整理期間重新整理的會話數。
"lastSessionsCollectionJobEntriesEnded" : 0, -- 在上一次重新整理期間結束的會話數。
"lastSessionsCollectionJobCursorsClosed" : 0, -- 在上一次config.system.sessions集合重新整理期間關閉的遊标數。
"transactionReaperJobCount" : 101, -- 跟蹤事務記錄清除過程已在config.transactions集合上運作的次數的數字。
"lastTransactionReaperJobDurationMillis" : 0, -- 上次事務記錄清除的長度(以毫秒為機關)
"lastTransactionReaperJobTimestamp" : ISODate("2020-08-13T09:17:55.863Z"), -- 上次事務記錄清除的時間
"lastTransactionReaperJobEntriesCleanedUp" : 0, -- config.transactions集合中上次事務記錄清除期間删除的條目數。
"sessionCatalogSize" : 0 -- 對于mongod執行個體,config.transactions條目的記憶體緩存大小;對于mongos執行個體:localLogicalSessionTimeoutMinutes内未過期的可重試寫入或事務
},
"network" : { -- MongoDB網絡使用情況資料的文檔。https://docs.mongodb.com/v4.2/reference/command/serverStatus/#network
"bytesIn" : NumberLong(25843431), -- 接收的網絡流量的位元組數
"bytesOut" : NumberLong(32178855), -- 發送的網絡流量的位元組數
"physicalBytesIn" : NumberLong(18156427),
"physicalBytesOut" : NumberLong(22163279),
"numRequests" : NumberLong(57762), -- 收到的不同請求的總數
"compression" : { -- 壓縮資訊
"snappy" : {
"compressor" : { -- compressor資訊
"bytesIn" : NumberLong(37694572),
"bytesOut" : NumberLong(26683033)
},
"decompressor" : { -- decompressor資訊
"bytesIn" : NumberLong(27727534),
"bytesOut" : NumberLong(41769607)
}
},
"zstd" : {
"compressor" : {
"bytesIn" : NumberLong(0),
"bytesOut" : NumberLong(0)
},
"decompressor" : {
"bytesIn" : NumberLong(0),
"bytesOut" : NumberLong(0)
}
},
"zlib" : {
"compressor" : {
"bytesIn" : NumberLong(0),
"bytesOut" : NumberLong(0)
},
"decompressor" : {
"bytesIn" : NumberLong(0),
"bytesOut" : NumberLong(0)
}
}
},
"serviceExecutorTaskStats" : {
"executor" : "passthrough",
"threadsRunning" : 11
}
},
"opLatencies" : { -- 僅适用于mongod執行個體,包含整個執行個體的操作延遲
"reads" : { -- 讀取請求的延遲統計資訊
"latency" : NumberLong(1140144),
"ops" : NumberLong(8506)
},
"writes" : { -- 寫入操作的延遲統計資訊
"latency" : NumberLong(0),
"ops" : NumberLong(0)
},
"commands" : { -- 資料庫指令的延遲統計資訊
"latency" : NumberLong(3201015),
"ops" : NumberLong(49254)
},
"transactions" : { -- 事務的延遲統計資訊
"latency" : NumberLong(0),
"ops" : NumberLong(0)
}
},
"opReadConcernCounters" : { -- 自上次啟動以來,向mongod執行個體報告查詢操作指定的讀取關注級别的文檔。
"available" : NumberLong(0), -- 指定讀取關注級别“可用”的查詢操作數
"linearizable" : NumberLong(0), -- 指定讀取關注級别“linearizable”的查詢操作數
"local" : NumberLong(2), -- 指定讀取關注級别“本地”的查詢操作數
"majority" : NumberLong(0), -- 指定讀取關注級别“多數”的查詢操作數
"snapshot" : NumberLong(0), -- 指定讀取關注級别“快照”的查詢操作數
"none" : NumberLong(111) -- 未指定讀關注級别,而是使用預設讀關注級别的查詢操作數。
},
"opcounters" : { -- 自mongod執行個體上次啟動以來按類型報告資料庫操作的文檔
"insert" : NumberLong(3), -- 自mongod執行個體上次啟動以來收到的插入操作總數
"query" : NumberLong(113), -- 自mongod執行個體上次啟動以來收到的查詢總數
"update" : NumberLong(9), -- 自mongod執行個體上次啟動以來收到的更新操作總數
"delete" : NumberLong(2), -- 自mongod執行個體上次啟動以來的删除操作總數
"getmore" : NumberLong(8489), -- 自上次啟動mongod執行個體以來,“getmore”操作的總數。即使查詢計數很低,此計數器也可能很高。輔助節點在複制過程中發送getMore操作。
"command" : NumberLong(49404) -- 自mongod執行個體上次啟動以來,釋出到資料庫的指令總數
},
"opcountersRepl" : { -- 自mongod執行個體上次啟動以來按類型報告資料庫複制操作的文檔,僅當目前主機是副本集的成員時,才會顯示這些值
"insert" : NumberLong(0), -- 插入總數
"query" : NumberLong(0), -- 查詢總數
"update" : NumberLong(0), -- 更新總數
"delete" : NumberLong(0), -- 删除總數
"getmore" : NumberLong(0), -- getmore總數
"command" : NumberLong(0) -- 指令總數
},
"oplogTruncation" : { -- 目前執行個體是副本集的成員并使用WiredTiger Storage Engine時,才顯示該字段。
"totalTimeProcessingMicros" : NumberLong(33), -- 掃描或采樣記錄檔以确定記錄檔截斷點所花費的總時間(以微秒為機關)
"processingMethod" : "scanning", -- 啟動時用于确定oplog截斷點的方法。 該值可以是“采樣”或“掃描”。
"totalTimeTruncatingMicros" : NumberLong(0), -- 執行oplog截斷所花費的累積時間(以微秒為機關)
"truncateCount" : NumberLong(0) -- oplog截斷的累積數量
},
"repl" : { -- 報告副本集配置的文檔。僅當目前主機是副本集時才會出現repl。
"hosts" : [ -- 成員主機名
"11.11.11.11:27017",
"11.11.11.12:27017",
"11.11.11.13:27017"
],
"setName" : "XYZ", -- 副本集名稱
"setVersion" : 1, -- 版本
"ismaster" : true, -- 目前節點是否為副本集的主節點
"secondary" : false, -- 目前節點是否為副本集的輔助節點
"primary" : "11.11.11.11:27017", -- 主節點位址
"me" : "11.11.11.11:27017", -- 目前執行的位址
"electionId" : ObjectId("7fffffff0000000000000001"),
"lastWrite" : {
"opTime" : { -- 該成員所報告的有關該成員所應用記錄檔中最後一次操作的資訊
"ts" : Timestamp(1597310423, 1),
"t" : NumberLong(1)
},
"lastWriteDate" : ISODate("2020-08-13T09:20:23Z"),
"majorityOpTime" : {
"ts" : Timestamp(1597310423, 1),
"t" : NumberLong(1)
},
"majorityWriteDate" : ISODate("2020-08-13T09:20:23Z")
},
"rbid" : 1 -- 復原辨別符。用于确定此mongod執行個體是否發生了復原
},
"storageEngine" : { -- 有關目前存儲引擎資料的文檔
"name" : "wiredTiger", -- 目前存儲引擎的名稱
"supportsCommittedReads" : true, -- 存儲引擎是否支援“多數”讀取關注的布爾值
"oldestRequiredTimestampForCrashRecovery" : Timestamp(1597310403, 1),
"supportsPendingDrops" : true,
"dropPendingIdents" : NumberLong(0),
"supportsSnapshotReadConcern" : true,
"readOnly" : false, -- 是否隻讀
"persistent" : true, -- 訓示存儲引擎是否将資料持久儲存到磁盤的布爾值
"backupCursorOpen" : false
},
"tcmalloc" : {
"generic" : {
"current_allocated_bytes" : 137730688,
"heap_size" : 176914432
},
"tcmalloc" : {
"pageheap_free_bytes" : 2736128,
"pageheap_unmapped_bytes" : 31244288,
"max_total_thread_cache_bytes" : 1024458752,
"current_total_thread_cache_bytes" : 1950976,
"total_free_bytes" : 5203328,
"central_cache_free_bytes" : 427840,
"transfer_cache_free_bytes" : 2824512,
"thread_cache_free_bytes" : 1950976,
"aggressive_memory_decommit" : 0,
"pageheap_committed_bytes" : 145670144,
"pageheap_scavenge_count" : 575,
"pageheap_commit_count" : 1376,
"pageheap_total_commit_bytes" : NumberLong(1139781632),
"pageheap_decommit_count" : 575,
"pageheap_total_decommit_bytes" : 994111488,
"pageheap_reserve_count" : 60,
"pageheap_total_reserve_bytes" : 176914432,
"spinlock_total_delay_ns" : 1320,
"release_rate" : 1,
"formattedString" : "------------------------------------------------\nMALLOC: 137731264 ( 131.4 MiB) Bytes in use by application\nMALLOC: + 2736128 ( 2.6 MiB) Bytes in page heap freelist\nMALLOC: + 427840 ( 0.4 MiB) Bytes in central cache freelist\nMALLOC: + 2824512 ( 2.7 MiB) Bytes in transfer cache freelist\nMALLOC: + 1950400 ( 1.9 MiB) Bytes in thread cache freelists\nMALLOC: + 2883584 ( 2.8 MiB) Bytes in malloc metadata\nMALLOC: ------------\nMALLOC: = 148553728 ( 141.7 MiB) Actual memory used (physical + swap)\nMALLOC: + 31244288 ( 29.8 MiB) Bytes released to OS (aka unmapped)\nMALLOC: ------------\nMALLOC: = 179798016 ( 171.5 MiB) Virtual address space used\nMALLOC:\nMALLOC: 1434 Spans in use\nMALLOC: 71 Thread heaps in use\nMALLOC: 4096 Tcmalloc page size\n------------------------------------------------\nCall ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).\nBytes released to the OS take up virtual address space but no physical memory.\n"
}
},
"trafficRecording" : { -- 輸出中包括trafficRecording名額
"running" : false
},
"transactions" : { -- 包含有關事務資料的文檔,在3.6.3+的mongod和4.2+的mongos中可用。https://docs.mongodb.com/v4.2/reference/command/serverStatus/#transactions
"retriedCommandsCount" : NumberLong(0), -- 僅在mongod上可用。在已經送出了相應的可重試寫入指令之後,已接收到的重試嘗試總數。
"retriedStatementsCount" : NumberLong(0), -- 寫語句總數,與transaction.retriedCommandsCount中重試的指令相關聯
"transactionsCollectionWriteCount" : NumberLong(0), -- 僅在mongod上可用,送出新的可重試的寫語句時觸發對config.transactions集合的寫總數
"currentActive" : NumberLong(0), -- 目前正在執行的事務總數
"currentInactive" : NumberLong(0), -- 目前未執行指令的事務總數
"currentOpen" : NumberLong(0), -- 目前打開事務的總數
"totalAborted" : NumberLong(0), -- 執行個體自上次啟動以來中止的事務總數
"totalCommitted" : NumberLong(0), -- 執行個體自上次啟動以來在執行個體上送出的事務總數
"totalStarted" : NumberLong(0), -- 執行個體自上次啟動以來在執行個體上啟動的事務總數
"totalPrepared" : NumberLong(0), -- 執行個體自上次啟動以來在伺服器上處于準備狀态的事務總數
"totalPreparedThenCommitted" : NumberLong(0), -- 執行個體自上次啟動以來在伺服器上準備并送出的事務總數
"totalPreparedThenAborted" : NumberLong(0), -- 執行個體自上次啟動以來在伺服器上準備并中止的事務總數
"currentPrepared" : NumberLong(0) -- 伺服器上處于準備狀态的目前事務數
},
"transportSecurity" : { -- 建立的TLS <version>連接配接的累積數量。 重新啟動後将重置該值。
"1.0" : NumberLong(0),
"1.1" : NumberLong(0),
"1.2" : NumberLong(0),
"1.3" : NumberLong(0),
"unknown" : NumberLong(0)
},
"twoPhaseCommitCoordinator" : { -- 二階段送出資訊
"totalCreated" : NumberLong(0),
"totalStartedTwoPhaseCommit" : NumberLong(0),
"totalAbortedTwoPhaseCommit" : NumberLong(0),
"totalCommittedTwoPhaseCommit" : NumberLong(0),
"currentInSteps" : {
"writingParticipantList" : NumberLong(0),
"waitingForVotes" : NumberLong(0),
"writingDecision" : NumberLong(0),
"waitingForDecisionAcks" : NumberLong(0),
"deletingCoordinatorDoc" : NumberLong(0)
}
},
"wiredTiger" : { -- 使用WiredTiger存儲引擎時資訊才會出現。一些統計彙總資訊。https://docs.mongodb.com/v4.2/reference/command/serverStatus/#wiredtiger
"uri" : "statistics:", -- 一個字元串。 供MongoDB内部使用。
"async" : { -- 傳回與異步操作API相關的統計資訊的文檔,MongoDB未使用它。
"current work queue length" : 0,
"maximum work queue length" : 0,
"number of allocation state races" : 0,
"number of flush calls" : 0,
"number of operation slots viewed for allocation" : 0,
"number of times operation allocation failed" : 0,
"number of times worker found no work" : 0,
"total allocations" : 0,
"total compact calls" : 0,
"total insert calls" : 0,
"total remove calls" : 0,
"total search calls" : 0,
"total update calls" : 0
},
"block-manager" : { -- 傳回有關塊管理器操作的統計資訊的文檔
"blocks pre-loaded" : 0,
"blocks read" : 1458,
"blocks written" : 5954,
"bytes read" : 5971968,
"bytes written" : 39948288,
"bytes written for checkpoint" : 39948288,
"mapped blocks read" : 0,
"mapped bytes read" : 0
},
"cache" : { -- 有關緩存的統計資訊和來自緩存的頁面逐出的文檔
"application threads page read from disk to cache count" : 0,
"application threads page read from disk to cache time (usecs)" : 0,
"application threads page write from cache to disk count" : 2972,
"application threads page write from cache to disk time (usecs)" : 181330,
"bytes belonging to page images in the cache" : 43,
"bytes belonging to the cache overflow table in the cache" : 182,
"bytes currently in the cache" : 753495, -- 目前緩存中資料的位元組大小,該值不應大于配置的最大位元組數。
"bytes dirty in the cache cumulative" : 2438469,
"bytes not belonging to page images in the cache" : 753452,
"bytes read into cache" : 0,
"bytes written from cache" : 52711232,
"cache overflow cursor application thread wait time (usecs)" : 0,
"cache overflow cursor internal thread wait time (usecs)" : 0,
"cache overflow score" : 0,
"cache overflow table entries" : 0,
"cache overflow table insert calls" : 0,
"cache overflow table max on-disk size" : 0,
"cache overflow table on-disk size" : 0,
"cache overflow table remove calls" : 0,
"checkpoint blocked page eviction" : 0,
"eviction calls to get a page" : 1148,
"eviction calls to get a page found queue empty" : 1129,
"eviction calls to get a page found queue empty after locking" : 0,
"eviction currently operating in aggressive mode" : 0,
"eviction empty score" : 0,
"eviction passes of a file" : 0,
"eviction server candidate queue empty when topping up" : 0,
"eviction server candidate queue not empty when topping up" : 0,
"eviction server evicting pages" : 0,
"eviction server slept, because we did not make progress with eviction" : 1056,
"eviction server unable to reach eviction goal" : 0,
"eviction server waiting for a leaf page" : 4,
"eviction state" : 128,
"eviction walk target pages histogram - 0-9" : 0,
"eviction walk target pages histogram - 10-31" : 0,
"eviction walk target pages histogram - 128 and higher" : 0,
"eviction walk target pages histogram - 32-63" : 0,
"eviction walk target pages histogram - 64-128" : 0,
"eviction walk target strategy both clean and dirty pages" : 0,
"eviction walk target strategy only clean pages" : 0,
"eviction walk target strategy only dirty pages" : 0,
"eviction walks abandoned" : 0,
"eviction walks gave up because they restarted their walk twice" : 0,
"eviction walks gave up because they saw too many pages and found no candidates" : 0,
"eviction walks gave up because they saw too many pages and found too few candidates" : 0,
"eviction walks reached end of tree" : 0,
"eviction walks started from root of tree" : 0,
"eviction walks started from saved location in tree" : 0,
"eviction worker thread active" : 4,
"eviction worker thread created" : 0,
"eviction worker thread evicting pages" : 3,
"eviction worker thread removed" : 0,
"eviction worker thread stable number" : 0,
"files with active eviction walks" : 0,
"files with new eviction walks started" : 0,
"force re-tuning of eviction workers once in a while" : 0,
"forced eviction - pages evicted that were clean count" : 0,
"forced eviction - pages evicted that were clean time (usecs)" : 0,
"forced eviction - pages evicted that were dirty count" : 2,
"forced eviction - pages evicted that were dirty time (usecs)" : 56,
"forced eviction - pages selected because of too many deleted items count" : 5,
"forced eviction - pages selected count" : 2,
"forced eviction - pages selected unable to be evicted count" : 0,
"forced eviction - pages selected unable to be evicted time" : 0,
"hazard pointer blocked page eviction" : 0,
"hazard pointer check calls" : 5,
"hazard pointer check entries walked" : 0,
"hazard pointer maximum array length" : 0,
"in-memory page passed criteria to be split" : 0,
"in-memory page splits" : 0,
"internal pages evicted" : 0,
"internal pages queued for eviction" : 0,
"internal pages seen by eviction walk" : 0,
"internal pages seen by eviction walk that are already queued" : 0,
"internal pages split during eviction" : 0,
"leaf pages split during eviction" : 0,
"maximum bytes configured" : 1073741824, -- 已配置wiredTiger.cache.maximum位元組,最大緩存大小
"maximum page size at eviction" : 0,
"modified pages evicted" : 7,
"modified pages evicted by application threads" : 0,
"operations timed out waiting for space in cache" : 0,
"overflow pages read into cache" : 0,
"page split during eviction deepened the tree" : 0,
"page written requiring cache overflow records" : 0,
"pages currently held in the cache" : 59,
"pages evicted by application threads" : 0,
"pages queued for eviction" : 0,
"pages queued for eviction post lru sorting" : 0,
"pages queued for urgent eviction" : 5,
"pages queued for urgent eviction during walk" : 0,
"pages read into cache" : 0, -- 讀入緩存的頁面數,從緩存寫入的wiredTiger.cache.pages讀取到緩存的wiredTiger.cache.pages(IO)。
"pages read into cache after truncate" : 30,
"pages read into cache after truncate in prepare state" : 0,
"pages read into cache requiring cache overflow entries" : 0,
"pages read into cache requiring cache overflow for checkpoint" : 0,
"pages read into cache skipping older cache overflow entries" : 0,
"pages read into cache with skipped cache overflow entries needed later" : 0,
"pages read into cache with skipped cache overflow entries needed later by checkpoint" : 0,
"pages requested from the cache" : 234580,
"pages seen by eviction walk" : 0,
"pages seen by eviction walk that are already queued" : 0,
"pages selected for eviction unable to be evicted" : 0,
"pages selected for eviction unable to be evicted as the parent page has overflow items" : 0,
"pages selected for eviction unable to be evicted because of active children on an internal page" : 0,
"pages selected for eviction unable to be evicted because of failure in reconciliation" : 0,
"pages selected for eviction unable to be evicted due to newer modifications on a clean page" : 0,
"pages walked for eviction" : 0,
"pages written from cache" : 2972, -- 從緩存寫入的頁面數,從緩存寫入的wiredTiger.cache.pages和讀取到緩存中的wiredTiger.cache.pages(IO)。
"pages written requiring in-memory restoration" : 3,
"percentage overhead" : 8,
"tracked bytes belonging to internal pages in the cache" : 12935,
"tracked bytes belonging to leaf pages in the cache" : 740560,
"tracked dirty bytes in the cache" : 688182, -- 高速緩存中髒資料的大小(以位元組為機關),此值應小于緩存值中目前的位元組。
"tracked dirty pages in the cache" : 4, -- 高速緩存中髒資料頁數
"unmodified pages evicted" : 0 -- 頁面驅逐的主要統計資料
},
"capacity" : { -- 背景刷寫資訊
"background fsync file handles considered" : 0,
"background fsync file handles synced" : 0,
"background fsync time (msecs)" : 0,
"bytes read" : 0,
"bytes written for checkpoint" : 18069881,
"bytes written for eviction" : 0,
"bytes written for log" : 1635328,
"bytes written total" : 19705209,
"threshold to call fsync" : 0,
"time waiting due to total capacity (usecs)" : 0,
"time waiting during checkpoint (usecs)" : 0,
"time waiting during eviction (usecs)" : 0,
"time waiting during logging (usecs)" : 0,
"time waiting during read (usecs)" : 0
},
"connection" : { -- 傳回與WiredTiger連接配接有關的統計資訊的文檔
"auto adjusting condition resets" : 6370,
"auto adjusting condition wait calls" : 191658,
"detected system time went backwards" : 0,
"files currently open" : 34,
"memory allocations" : 2615516,
"memory frees" : 2607397,
"memory re-allocations" : 437367,
"pthread mutex condition wait calls" : 510231,
"pthread mutex shared lock read-lock calls" : 736461,
"pthread mutex shared lock write-lock calls" : 82147,
"total fsync I/Os" : 7277,
"total read I/Os" : 1970,
"total write I/Os" : 10269
},
"cursor" : { -- 在WiredTiger遊标上傳回統計資訊的文檔
"cached cursor count" : 43,
"cursor bulk loaded cursor insert calls" : 0,
"cursor close calls that result in cache" : 69336,
"cursor create calls" : 84645,
"cursor insert calls" : 5974,
"cursor insert key and value bytes" : 2708353,
"cursor modify calls" : 0,
"cursor modify key and value bytes affected" : 0,
"cursor modify value bytes modified" : 0,
"cursor next calls" : 86761,
"cursor operation restarted" : 0,
"cursor prev calls" : 479,
"cursor remove calls" : 19,
"cursor remove key bytes removed" : 484,
"cursor reserve calls" : 0,
"cursor reset calls" : 304050,
"cursor search calls" : 185985,
"cursor search near calls" : 591,
"cursor sweep buckets" : 26167,
"cursor sweep cursors closed" : 1,
"cursor sweep cursors examined" : 533,
"cursor sweeps" : 4361,
"cursor truncate calls" : 0,
"cursor update calls" : 0,
"cursor update key and value bytes" : 0,
"cursor update value size change" : 0,
"cursors reused from cache" : 68813,
"open cursor count" : 26
},
"data-handle" : { -- 傳回有關資料句柄和掃描的統計資訊的文檔。
"connection data handle size" : 432,
"connection data handles currently active" : 61,
"connection sweep candidate became referenced" : 0,
"connection sweep dhandles closed" : 1,
"connection sweep dhandles removed from hash list" : 1984,
"connection sweep time-of-death sets" : 5948,
"connection sweeps" : 3015,
"session dhandles swept" : 2,
"session sweep attempts" : 572
},
"lock" : {
"checkpoint lock acquisitions" : 503,
"checkpoint lock application thread wait time (usecs)" : 0,
"checkpoint lock internal thread wait time (usecs)" : 0,
"dhandle lock application thread time waiting (usecs)" : 0,
"dhandle lock internal thread time waiting (usecs)" : 0,
"dhandle read lock acquisitions" : 128469,
"dhandle write lock acquisitions" : 4030,
"durable timestamp queue lock application thread time waiting (usecs)" : 0,
"durable timestamp queue lock internal thread time waiting (usecs)" : 0,
"durable timestamp queue read lock acquisitions" : 0,
"durable timestamp queue write lock acquisitions" : 2822,
"metadata lock acquisitions" : 473,
"metadata lock application thread wait time (usecs)" : 0,
"metadata lock internal thread wait time (usecs)" : 0,
"read timestamp queue lock application thread time waiting (usecs)" : 1,
"read timestamp queue lock internal thread time waiting (usecs)" : 0,
"read timestamp queue read lock acquisitions" : 0,
"read timestamp queue write lock acquisitions" : 490,
"schema lock acquisitions" : 511,
"schema lock application thread wait time (usecs)" : 0,
"schema lock internal thread wait time (usecs)" : 0,
"table lock application thread time waiting for the table lock (usecs)" : 193,
"table lock internal thread time waiting for the table lock (usecs)" : 0,
"table read lock acquisitions" : 0,
"table write lock acquisitions" : 28145,
"txn global lock application thread time waiting (usecs)" : 0,
"txn global lock internal thread time waiting (usecs)" : 9,
"txn global read lock acquisitions" : 8837,
"txn global write lock acquisitions" : 12689
},
"log" : { -- 傳回WiredTiger的預寫日志(即日志)統計資訊的文檔,https://docs.mongodb.com/v4.2/core/journaling/#journaling-wiredtiger
"busy returns attempting to switch slots" : 0,
"force archive time sleeping (usecs)" : 0,
"log bytes of payload data" : 1181490,
"log bytes written" : 1635200,
"log files manually zero-filled" : 0,
"log flush operations" : 63118,
"log force write operations" : 96155,
"log force write operations skipped" : 92857,
"log records compressed" : 513,
"log records not compressed" : 2886,
"log records too small to compress" : 1446,
"log release advances write LSN" : 507,
"log scan operations" : 0,
"log scan records requiring two reads" : 0,
"log server thread advances write LSN" : 3298,
"log server thread write LSN walk skipped" : 48737,
"log sync operations" : 3806,
"log sync time duration (usecs)" : 4251984,
"log sync_dir operations" : 1,
"log sync_dir time duration (usecs)" : 1423,
"log write operations" : 4845,
"logging bytes consolidated" : 1634688,
"maximum log file size" : 104857600,
"number of pre-allocated log files to create" : 2,
"pre-allocated log files not ready and missed" : 1,
"pre-allocated log files prepared" : 2,
"pre-allocated log files used" : 0,
"records processed by log scan" : 0,
"slot close lost race" : 0,
"slot close unbuffered waits" : 0,
"slot closures" : 3805,
"slot join atomic update races" : 0,
"slot join calls atomic updates raced" : 0,
"slot join calls did not yield" : 4845,
"slot join calls found active slot closed" : 0,
"slot join calls slept" : 0,
"slot join calls yielded" : 0,
"slot join found active slot closed" : 0,
"slot joins yield time (usecs)" : 0,
"slot transitions unable to find free slot" : 0,
"slot unbuffered writes" : 0,
"total in-memory size of compressed records" : 2320998,
"total log buffer size" : 33554432,
"total size of compressed records" : 691677,
"written slots coalesced" : 0,
"yields waiting for previous log file close" : 0
},
"perf" : {
"file system read latency histogram (bucket 1) - 10-49ms" : 0,
"file system read latency histogram (bucket 2) - 50-99ms" : 0,
"file system read latency histogram (bucket 3) - 100-249ms" : 0,
"file system read latency histogram (bucket 4) - 250-499ms" : 0,
"file system read latency histogram (bucket 5) - 500-999ms" : 0,
"file system read latency histogram (bucket 6) - 1000ms+" : 0,
"file system write latency histogram (bucket 1) - 10-49ms" : 0,
"file system write latency histogram (bucket 2) - 50-99ms" : 0,
"file system write latency histogram (bucket 3) - 100-249ms" : 0,
"file system write latency histogram (bucket 4) - 250-499ms" : 0,
"file system write latency histogram (bucket 5) - 500-999ms" : 0,
"file system write latency histogram (bucket 6) - 1000ms+" : 0,
"operation read latency histogram (bucket 1) - 100-249us" : 0,
"operation read latency histogram (bucket 2) - 250-499us" : 0,
"operation read latency histogram (bucket 3) - 500-999us" : 0,
"operation read latency histogram (bucket 4) - 1000-9999us" : 0,
"operation read latency histogram (bucket 5) - 10000us+" : 0,
"operation write latency histogram (bucket 1) - 100-249us" : 0,
"operation write latency histogram (bucket 2) - 250-499us" : 0,
"operation write latency histogram (bucket 3) - 500-999us" : 0,
"operation write latency histogram (bucket 4) - 1000-9999us" : 0,
"operation write latency histogram (bucket 5) - 10000us+" : 0
},
"reconciliation" : { -- 傳回和解過程統計資訊的文檔
"fast-path pages deleted" : 0,
"page reconciliation calls" : 3000,
"page reconciliation calls for eviction" : 6,
"pages deleted" : 32,
"split bytes currently awaiting free" : 0,
"split objects currently awaiting free" : 0
},
"session" : { -- 傳回會話的打開遊标計數和打開會話數的文檔。
"open session count" : 21,
"session query timestamp calls" : 0,
"table alter failed calls" : 0,
"table alter successful calls" : 0,
"table alter unchanged and skipped" : 0,
"table compact failed calls" : 0,
"table compact successful calls" : 0,
"table create failed calls" : 0,
"table create successful calls" : 30,
"table drop failed calls" : 0,
"table drop successful calls" : 1,
"table import failed calls" : 0,
"table import successful calls" : 0,
"table rebalance failed calls" : 0,
"table rebalance successful calls" : 0,
"table rename failed calls" : 0,
"table rename successful calls" : 0,
"table salvage failed calls" : 0,
"table salvage successful calls" : 0,
"table truncate failed calls" : 0,
"table truncate successful calls" : 0,
"table verify failed calls" : 0,
"table verify successful calls" : 0
},
"thread-state" : {
"active filesystem fsync calls" : 0,
"active filesystem read calls" : 0,
"active filesystem write calls" : 0
},
"thread-yield" : { -- 在頁面擷取過程中傳回産量統計資訊的文檔
"application thread time evicting (usecs)" : 0,
"application thread time waiting for cache (usecs)" : 0,
"connection close blocked waiting for transaction state stabilization" : 0,
"connection close yielded for lsm manager shutdown" : 0,
"data handle lock yielded" : 0,
"get reference for page index and slot time sleeping (usecs)" : 0,
"log server sync yielded for log write" : 0,
"page access yielded due to prepare state change" : 0,
"page acquire busy blocked" : 0,
"page acquire eviction blocked" : 0,
"page acquire locked blocked" : 0,
"page acquire read blocked" : 0,
"page acquire time sleeping (usecs)" : 0,
"page delete rollback time sleeping for state change (usecs)" : 0,
"page reconciliation yielded due to child modification" : 0
},
"transaction" : { -- 傳回有關事務檢查點和操作的統計資訊的文檔
"Number of prepared updates" : 0,
"Number of prepared updates added to cache overflow" : 0,
"durable timestamp queue entries walked" : 1085,
"durable timestamp queue insert to empty" : 1737,
"durable timestamp queue inserts to head" : 1085,
"durable timestamp queue inserts total" : 2822,
"durable timestamp queue length" : 1,
"number of named snapshots created" : 0,
"number of named snapshots dropped" : 0,
"prepared transactions" : 0,
"prepared transactions committed" : 0,
"prepared transactions currently active" : 0,
"prepared transactions rolled back" : 0,
"query timestamp calls" : 92170,
"read timestamp queue entries walked" : 248,
"read timestamp queue insert to empty" : 242,
"read timestamp queue inserts to head" : 248,
"read timestamp queue inserts total" : 490,
"read timestamp queue length" : 1,
"rollback to stable calls" : 0,
"rollback to stable updates aborted" : 0,
"rollback to stable updates removed from cache overflow" : 0,
"set timestamp calls" : 5636,
"set timestamp durable calls" : 0,
"set timestamp durable updates" : 0,
"set timestamp oldest calls" : 2818,
"set timestamp oldest updates" : 2818,
"set timestamp stable calls" : 2818,
"set timestamp stable updates" : 2818,
"transaction begins" : 87358,
"transaction checkpoint currently running" : 0,
"transaction checkpoint generation" : 474,
"transaction checkpoint max time (msecs)" : 35,
"transaction checkpoint min time (msecs)" : 5,
"transaction checkpoint most recent time (msecs)" : 12, -- 建立最新檢查點的時間(以毫秒為機關)。在穩定的寫負載下,該值的增加可能表示IO子系統已飽和。
"transaction checkpoint scrub dirty target" : 0,
"transaction checkpoint scrub time (msecs)" : 0,
"transaction checkpoint total time (msecs)" : 5855,
"transaction checkpoints" : 503,
"transaction checkpoints skipped because database was clean" : 30,
"transaction failures due to cache overflow" : 0,
"transaction fsync calls for checkpoint after allocating the transaction ID" : 473,
"transaction fsync duration for checkpoint after allocating the transaction ID (usecs)" : 3815,
"transaction range of IDs currently pinned" : 0,
"transaction range of IDs currently pinned by a checkpoint" : 0,
"transaction range of IDs currently pinned by named snapshots" : 0,
"transaction range of timestamps currently pinned" : 21474836480,
"transaction range of timestamps pinned by a checkpoint" : NumberLong("6860396028344926209"),
"transaction range of timestamps pinned by the oldest active read timestamp" : 0,
"transaction range of timestamps pinned by the oldest timestamp" : 21474836480,
"transaction read timestamp of the oldest active reader" : 0,
"transaction sync calls" : 0,
"transactions committed" : 3318,
"transactions rolled back" : 84391,
"update conflicts" : 0
},
"concurrentTransactions" : { -- 傳回有關允許WiredTiger存儲引擎進行的并發讀寫事務數的資訊
"write" : {
"out" : 0,
"available" : 128,
"totalTickets" : 128
},
"read" : {
"out" : 1,
"available" : 127,
"totalTickets" : 128
}
},
"snapshot-window-settings" : {
"cache pressure percentage threshold" : 95,
"current cache pressure percentage" : NumberLong(0),
"total number of SnapshotTooOld errors" : NumberLong(0),
"max target available snapshots window size in seconds" : 5,
"target available snapshots window size in seconds" : 5,
"current available snapshots window size in seconds" : 5,
"latest majority snapshot timestamp available" : "Aug 13 17:20:23:1",
"oldest majority snapshot timestamp available" : "Aug 13 17:20:18:1"
},
"oplog" : {
"visibility timestamp" : Timestamp(1597310423, 1)
}
},
"mem" : { -- 有關mongod的系統體系結構和目前記憶體使用情況的文檔
"bits" : 64, -- DB執行個體是64位還是32位體系結構編譯的。
"resident" : 89, -- 大緻等于資料庫程序目前使用的RAM量(以M為機關)。在正常使用期間,該值趨于增加。在專用資料庫伺服器中,此數字趨向于接近系統記憶體總量。
"virtual" : 1879, -- 顯示mongod程序使用的虛拟記憶體量(以M為機關)。
"supported" : true -- 是否支援擴充的記憶體資訊
},
"metrics" : { -- 傳回各種統計資訊的文檔,這些統計資訊反映了正在運作的mongod執行個體的目前使用情況和狀态。
"aggStageCounters" : { -- 報告聚合管道階段使用情況的文檔。 其中的字段是聚合管道階段的名稱,報告該階段已執行的次數。
"$_internalInhibitOptimization" : NumberLong(0),
"$_internalSplitPipeline" : NumberLong(0),
"$addFields" : NumberLong(0),
"$bucket" : NumberLong(0),
"$bucketAuto" : NumberLong(0),
"$changeStream" : NumberLong(0),
"$collStats" : NumberLong(0),
"$count" : NumberLong(0),
"$currentOp" : NumberLong(3),
"$facet" : NumberLong(0),
"$geoNear" : NumberLong(0),
"$graphLookup" : NumberLong(0),
"$group" : NumberLong(3),
"$indexStats" : NumberLong(0),
"$limit" : NumberLong(0),
"$listLocalSessions" : NumberLong(0),
"$listSessions" : NumberLong(0),
"$lookup" : NumberLong(0),
"$match" : NumberLong(3),
"$merge" : NumberLong(0),
"$mergeCursors" : NumberLong(0),
"$out" : NumberLong(0),
"$planCacheStats" : NumberLong(0),
"$project" : NumberLong(0),
"$redact" : NumberLong(0),
"$replaceRoot" : NumberLong(0),
"$replaceWith" : NumberLong(0),
"$sample" : NumberLong(0),
"$set" : NumberLong(0),
"$skip" : NumberLong(0),
"$sort" : NumberLong(0),
"$sortByCount" : NumberLong(0),
"$unset" : NumberLong(0),
"$unwind" : NumberLong(0)
},
"commands" : { -- 報告指令使用情況的文檔。 其中的字段是資料庫指令的名稱。 對于每個指令,報告執行的總數和失敗的執行次數。
"<UNKNOWN>" : NumberLong(0),
"_addShard" : {
"failed" : NumberLong(0), -- 失敗的次數
"total" : NumberLong(0) -- 執行的次數
},
"_cloneCatalogData" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_cloneCollectionOptionsFromPrimaryShard" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrAddShard" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrAddShardToZone" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrBalancerStart" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrBalancerStatus" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrBalancerStop" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrClearJumboFlag" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrCommitChunkMerge" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrCommitChunkMigration" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrCommitChunkSplit" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrCommitMovePrimary" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrCreateCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrCreateDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrDropCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrDropDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrEnableSharding" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrMoveChunk" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrMovePrimary" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrRemoveShard" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrRemoveShardFromZone" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrShardCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_configsvrUpdateZoneKeyRange" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_flushDatabaseCacheUpdates" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_flushRoutingTableCacheUpdates" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_getNextSessionMods" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_getUserCacheGeneration" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_isSelf" : {
"failed" : NumberLong(0),
"total" : NumberLong(2)
},
"_mergeAuthzCollections" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_migrateClone" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_movePrimary" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_recvChunkAbort" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_recvChunkCommit" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_recvChunkStart" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_recvChunkStatus" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_shardsvrShardCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"_transferMods" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"abortTransaction" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"aggregate" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"appendOplogNote" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"applyOps" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"authenticate" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"availableQueryOptions" : {
"failed" : NumberLong(0),
"total" : NumberLong(2)
},
"buildInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(45)
},
"checkShardingIndex" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"cleanupOrphaned" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"cloneCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"cloneCollectionAsCapped" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"collMod" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"collStats" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"commitTransaction" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"compact" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"connPoolStats" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"connPoolSync" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"connectionStatus" : {
"failed" : NumberLong(0),
"total" : NumberLong(3)
},
"convertToCapped" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"coordinateCommitTransaction" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"count" : {
"failed" : NumberLong(0),
"total" : NumberLong(2)
},
"create" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"createIndexes" : {
"failed" : NumberLong(0),
"total" : NumberLong(1)
},
"createRole" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"createUser" : {
"failed" : NumberLong(0),
"total" : NumberLong(1)
},
"currentOp" : {
"failed" : NumberLong(0),
"total" : NumberLong(3)
},
"dataSize" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dbHash" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dbStats" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"delete" : {
"failed" : NumberLong(0),
"total" : NumberLong(2)
},
"distinct" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"driverOIDTest" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"drop" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dropAllRolesFromDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dropAllUsersFromDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dropConnections" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dropDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dropIndexes" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dropRole" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"dropUser" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"endSessions" : {
"failed" : NumberLong(0),
"total" : NumberLong(2)
},
"explain" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"features" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"filemd5" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"find" : {
"failed" : NumberLong(0),
"total" : NumberLong(113)
},
"findAndModify" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"flushRouterConfig" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"fsync" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"fsyncUnlock" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"geoSearch" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"getCmdLineOpts" : {
"failed" : NumberLong(0),
"total" : NumberLong(7)
},
"getDatabaseVersion" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"getDiagnosticData" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"getFreeMonitoringStatus" : {
"failed" : NumberLong(0),
"total" : NumberLong(6)
},
"getLastError" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"getLog" : {
"failed" : NumberLong(0),
"total" : NumberLong(6)
},
"getMore" : {
"failed" : NumberLong(0),
"total" : NumberLong(8489)
},
"getParameter" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"getShardMap" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"getShardVersion" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"getnonce" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"grantPrivilegesToRole" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"grantRolesToRole" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"grantRolesToUser" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"hostInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"insert" : {
"failed" : NumberLong(0),
"total" : NumberLong(3)
},
"invalidateUserCache" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"isMaster" : {
"failed" : NumberLong(0),
"total" : NumberLong(2456)
},
"killAllSessions" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"killAllSessionsByPattern" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"killCursors" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"killOp" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"killSessions" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"listCollections" : {
"failed" : NumberLong(0),
"total" : NumberLong(21)
},
"listCommands" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"listDatabases" : {
"failed" : NumberLong(0),
"total" : NumberLong(4)
},
"listIndexes" : {
"failed" : NumberLong(9),
"total" : NumberLong(197)
},
"lockInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"logRotate" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"logout" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"mapReduce" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"mapreduce" : {
"shardedfinish" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
}
},
"mergeChunks" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"moveChunk" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"ping" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"planCacheClear" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"planCacheClearFilters" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"planCacheListFilters" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"planCacheListPlans" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"planCacheListQueryShapes" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"planCacheSetFilter" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"prepareTransaction" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"profile" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"reIndex" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"refreshSessions" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"renameCollection" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"repairCursor" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"repairDatabase" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetAbortPrimaryCatchUp" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetFreeze" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetGetConfig" : {
"failed" : NumberLong(0),
"total" : NumberLong(9)
},
"replSetGetRBID" : {
"failed" : NumberLong(0),
"total" : NumberLong(5)
},
"replSetGetStatus" : {
"failed" : NumberLong(7),
"total" : NumberLong(87)
},
"replSetHeartbeat" : {
"failed" : NumberLong(0),
"total" : NumberLong(28146)
},
"replSetInitiate" : {
"failed" : NumberLong(0),
"total" : NumberLong(1)
},
"replSetMaintenance" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetReconfig" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetRequestVotes" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetResizeOplog" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetStepDown" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetStepDownWithForce" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetStepUp" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetSyncFrom" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"replSetUpdatePosition" : {
"failed" : NumberLong(0),
"total" : NumberLong(15491)
},
"resetError" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"revokePrivilegesFromRole" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"revokeRolesFromRole" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"revokeRolesFromUser" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"rolesInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"saslContinue" : {
"failed" : NumberLong(0),
"total" : NumberLong(1924)
},
"saslStart" : {
"failed" : NumberLong(1),
"total" : NumberLong(963)
},
"serverStatus" : {
"failed" : NumberLong(0),
"total" : NumberLong(5)
},
"setFeatureCompatibilityVersion" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"setFreeMonitoring" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"setParameter" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"setShardVersion" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"shardConnPoolStats" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"shardingState" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"shutdown" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"splitChunk" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"splitVector" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"startRecordingTraffic" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"startSession" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"stopRecordingTraffic" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"top" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"touch" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"unsetSharding" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"update" : {
"failed" : NumberLong(0),
"total" : NumberLong(9)
},
"updateRole" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"updateUser" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"usersInfo" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"validate" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"voteCommitIndexBuild" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"waitForFailPoint" : {
"failed" : NumberLong(0),
"total" : NumberLong(0)
},
"whatsmyuri" : {
"failed" : NumberLong(0),
"total" : NumberLong(15)
}
},
"cursor" : { -- 包含有關遊标狀态和使用的資料的文檔
"timedOut" : NumberLong(2), -- 自伺服器程序啟動以來已逾時的遊标總數。如果此數字很大或以固定速度增長,則可能表明應用程式錯誤。
"open" : { -- 包含有關打開的遊标的資料的文檔
"noTimeout" : NumberLong(0),-- 選項DBQuery.Option.noTimeout的打開遊标的數量,以防止一段時間不活動後發生逾時。
"pinned" : NumberLong(1), -- “固定”打開的遊标的數量
"total" : NumberLong(1) -- MongoDB為用戶端維護的遊标數
}
},
"document" : { -- 反映文檔通路和修改的總數
"deleted" : NumberLong(1), -- 删除的文檔總數
"inserted" : NumberLong(3), -- 插入的文檔總數
"returned" : NumberLong(2840), -- 查詢傳回的文檔總數
"updated" : NumberLong(3) -- 更新的文檔總數
},
"getLastError" : { -- 報告getLastError使用情況的文檔
"wtime" : { -- 報告getLastError操作的文檔的w參數大于1
"num" : 13, -- 等待副本集的一個或多個成員确認寫操作(即w值大于1)的具有指定寫關注點(即w)的getLastError操作的總數。
"totalMillis" : 204 -- 消耗總時間(以毫秒為機關),該時間以寫關注點(即w)執行等待複制副本的一個或多個成員确認寫操作(即w值大于1)的getLastError操作。
},
"wtimeouts" : NumberLong(0) -- 由于getLastError的wtimeout門檻值,導緻寫入關注操作逾時的次數
},
"operation" : { -- 包含MongoDB使用特殊操作類型處理的計數器。
"scanAndOrder" : NumberLong(1), -- 傳回無法使用索引執行排序操作的排序數字的查詢總數
"writeConflicts" : NumberLong(0)-- 遇到寫沖突的查詢總數
},
"query" : {
"planCacheTotalSizeEstimateBytes" : NumberLong(0),
"updateOneOpStyleBroadcastWithExactIDCount" : NumberLong(0)
},
"queryExecutor" : { -- 報告來自查詢執行系統的資料的文檔
"scanned" : NumberLong(6), -- 在查詢和查詢計劃評估期間掃描的索引項總數。 該計數器與explain()輸出中的totalKeysExamined相同。
"scannedObjects" : NumberLong(2841) -- 在查詢和查詢計劃評估期間掃描的文檔總數。 該計數器與explain()輸出中的totalDocsExamined相同。
},
"record" : { -- 報告磁盤上的記憶體檔案中與記錄配置設定有關的資料的文檔
"moves" : NumberLong(0)
},
"repl" : { -- 報告與複制過程相關的名額的文檔
"executor" : {
"pool" : {
"inProgressCount" : 0
},
"queues" : {
"networkInProgress" : 0,
"sleepers" : 3
},
"unsignaledEvents" : 0,
"shuttingDown" : false,
"networkInterface" : "DEPRECATED: getDiagnosticString is deprecated in NetworkInterfaceTL"
},
"apply" : { -- 報告複制記錄檔中的操作應用程式的文檔
"attemptsToBecomeSecondary" : NumberLong(1),
"batchSize" : NumberLong(0), -- 應用的oplog操作總數。在批處理邊界處随批進行中的操作數增加,而不是在每次操作後均增加一
"batches" : { -- 有關副本集的輔助成員的oplog應用程式過程的報告
"num" : 0, -- 所有資料庫應用的批次總數
"totalMillis" : 0 -- 從記錄檔應用操作所花費的總時間(以毫秒為機關)
},
"ops" : NumberLong(0) -- 應用的oplog操作總數
},
"buffer" : { -- 在批量應用oplog條目之前,MongoDB會從複制同步源緩沖區中緩沖oplog操作
"count" : NumberLong(0), -- oplog緩沖區中的目前操作數
"maxSizeBytes" : NumberLong(268435456), -- oplog緩沖區的最大大小,不可配置
"sizeBytes" : NumberLong(0) -- oplog緩沖區内容的目前大小
},
"initialSync" : {
"completed" : NumberLong(0),
"failedAttempts" : NumberLong(0),
"failures" : NumberLong(0)
},
"network" : { -- 報告複制過程中的網絡使用情況
"bytes" : NumberLong(0), -- 報告從複制同步源讀取的資料總量
"getmores" : { -- 報告有關getmore操作的資訊,這些操作是記錄檔複制過程的一部分,要求記錄檔遊标提供其他結果
"num" : 0, -- 報告getmore操作的總數,這些操作是從複制同步源請求其他操作集的操作
"totalMillis" : 0 -- 報告從getmore操作收集資料所需的總時間
},
"notMasterLegacyUnacknowledgedWrites" : NumberLong(0), -- 由于目前mongod不在PRIMARY狀态而失敗的未确認(w:0)舊寫入操作數。
"notMasterUnacknowledgedWrites" : NumberLong(0), -- 由于目前mongod不在PRIMARY狀态而失敗的未确認(w:0)寫操作數。
"ops" : NumberLong(0), -- 從複制源讀取的操作總數
"readersCreated" : NumberLong(0), -- 建立的oplog查詢程序的總數
"replSetUpdatePosition" : {
"num" : NumberLong(0)
}
},
"stateTransition" : { -- 成員狀态轉換的使用者操作資訊
"lastStateTransition" : "stepUp", -- 成員狀态轉換說明。stepUp:主;stepDown:副本;rollback:復原
"userOperationsKilled" : NumberLong(0), -- 執行個體狀态更改期間殺死的使用者操作數
"userOperationsRunning" : NumberLong(0) -- 狀态更改期間保持運作的使用者操作數
},
"syncSource" : {
"numSelections" : NumberLong(11),
"numTimesChoseDifferent" : NumberLong(0),
"numTimesChoseSame" : NumberLong(0),
"numTimesCouldNotFind" : NumberLong(11)
}
},
"ttl" : {
"deletedDocuments" : NumberLong(3),
"passes" : NumberLong(469)
}
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1597310423, 1),
"signature" : {
"hash" : BinData(0,"oyQFyHGe1RHLqSQkSNOrDlZ8gyg="),
"keyId" : NumberLong("6860275335468941315")
}
},
"operationTime" : Timestamp(1597310423, 1)
}
可以檢視通過子項來進行針對資訊的檢視:
- 檢視鎖資訊:db.runCommand( { serverStatus: 1 } ).locks
- 檢視全局鎖:db.runCommand( { serverStatus: 1 } ).globalLock
- 檢視記憶體資訊:db.runCommand( { serverStatus: 1 } ).mem
- 檢視連接配接資訊:db.runCommand( { serverStatus: 1 } ).connections
- 檢視網絡資訊:db.runCommand( { serverStatus: 1, repl: 1, metrics: 1, locks: 1 } ).network
- 檢視操作資訊:db.runCommand( { serverStatus: 1, repl: 1, metrics: 1, locks: 1 } ).opcounters
- 檢視複制資訊:db.runCommand( { serverStatus: 1, repl: 1, metrics: 1, locks: 1 } ).repl
- 檢視複制內建員的操作資訊:db.runCommand( { serverStatus: 1, repl: 1, metrics: 1, locks: 1 } ).opcountersRepl
根據自己的需要來檢視相應的資訊,并且可以通過該指令來進行監控名額的定制。
rs.
initiate
(cfg):根據配置初始化副本集。
rs.conf() == db.adminCommand({replSetGetConfig:1}):傳回副本集的配置文檔。

XYZ:PRIMARY> db.adminCommand({replSetGetConfig:1})
{
"config" : {
"_id" : "XYZ", -- 副本集名
"version" : 1, -- 遞增的數字,用于區分副本集配置版本
"protocolVersion" : NumberLong(1), -- 副本集協定版本,從4.0開始,MongoDB僅支援protocolVersion:1,并且不再支援protocolVersion:0。
"writeConcernMajorityJournalDefault" : true, -- 如果寫關注未明确指定日記選項j,則确定{w:"majority"}寫關注的行為。true:在大多數有投票權的成員将其寫入磁盤日志後才确認該寫入操作。false:在大多數投票成員在記憶體中應用了該操作之後才确認該寫操作。
"members" : [ -- 副本內建員
{
"_id" : 0, -- 成員辨別,範圍是0~255。
"host" : "11.11.11.11:27017", -- 成員位址
"arbiterOnly" : false, -- 是否為仲裁節點
"buildIndexes" : true, -- 是否在成員上建立索引,對于接受查詢的執行個體,不能設定成false。如果設定為false,priority也需要是0,并且不能從該成員上進行複制
"hidden" : false, -- 是否為隐藏節點
"priority" : 1, -- 優先級,越大優先級越高,範圍是0~1000
"tags" : { -- 标簽,用來寫關注
},
"slaveDelay" : NumberLong(0), -- 是否為延遲節點
"votes" : 1 -- 是否有投票權限
},
{
"_id" : 1,
"host" : "11.11.11.12:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "11.11.11.13:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : { -- 相關設定
"chainingAllowed" : true, --是否支援鍊式複制,true:副本集允許輔助成員從其他輔助成員進行複制;false:輔助伺服器隻能從主伺服器複制
"heartbeatIntervalMillis" : 2000, -- 心跳間隔,機關毫秒
"heartbeatTimeoutSecs" : 10, -- 心跳逾時時間
"electionTimeoutMillis" : 10000, -- 選舉檢測副本集主資料庫何時不可用的時間限制(以毫秒為機關),機關毫秒。在protocolVersion為1是可用。參數enableElectionHandoff為true,rs.stepDown會立即選舉。不然等10s選舉。
"catchUpTimeoutMillis" : -1, -- 新選擇的主資料庫與其他可能具有更近期寫入操作的副本內建員同步(追趕)的時間限制(以毫秒為機關)-1:無限追趕時間。在protocolVersion為1是可用。版本3.6中啟動的副本集降級為3.4,請将catchUpTimeoutMillis從-1更改為正數,不然導緻運作版本3.4的節點既不重新啟動也不加入副本集。
"catchUpTakeoverDelayMillis" : 30000, -- 新選擇的主資料庫追趕的逾時時間,機關毫秒。在改時間内未完成追趕則目前主節點之前的節點會發起選舉以成為副本集的新主節點
"getLastErrorModes" : { -- 自定義寫關注點的文檔,<number>是指滿足寫關注所需的不同标簽值的數量。定義好的寫關注名字,可以帶入到getLastErrorDefaults參數中的w選項。
<name of write concern> : { <tag1>: <number>, .... }, -- 參考 https://docs.mongodb.com/v4.2/tutorial/configure-replica-set-tag-sets/
...
},
"getLastErrorDefaults" : { -- 寫關注文檔,如未設定,則副本集的預設寫關注僅需要主資料庫的确認。可以設定getLastErrorModes定義的。
-- https://docs.mongodb.com/v4.2/reference/write-concern/
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("5f3498078ce4089ec0948365") -- 自動建立的ObjectId
}
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1597297052, 1),
"signature" : {
"hash" : BinData(0,"LqYQwo/Nrx+gQrnnzJnYRMf8+78="),
"keyId" : NumberLong("6860275335468941315")
}
},
"operationTime" : Timestamp(1597297052, 1) -- 操作執行時間
}
rs.status() == db.adminCommand({replSetGetStatus:1}):檢視副本集狀态。

XYZ:PRIMARY> db.adminCommand({replSetGetStatus:1})
{
"set" : "XYZ", -- 複制集名(replSetName)
"date" : ISODate("2020-08-13T02:24:38.530Z"), -- 目前時間
"myState" : 1, -- 0到10之間的整數,表示目前成員的副本狀态:https://docs.mongodb.com/manual/reference/replica-states/
"term" : NumberLong(1), -- 副本內建員的選舉計數
"syncingTo" : "", -- 在MongoDB 4.4中删除,同syncSourceHost
"syncSourceHost" : "", -- 同步的成員的主機名
"syncSourceId" : -1, -- 如果此執行個體是主執行個體,則syncSourceHost為空字元串,且syncSourceId -1
"heartbeatIntervalMillis" : NumberLong(2000), -- 心跳的頻率(以毫秒為機關)
"majorityVoteCount" : 2, -- 選舉中所需的多數票的數字
"writeMajorityCount" : 2, -- 滿足寫關注“多數”需要的投票成員(即非仲裁員)的數量
"optimes" : {
"lastCommittedOpTime" : { -- 寫入大多數副本內建員的最新操作的資訊
"ts" : Timestamp(1597285472, 1), -- 時間戳
"t" : NumberLong(1) -- 一個term裡主上生成操作的次數
},
"lastCommittedWallTime" : ISODate("2020-08-13T02:24:32.634Z"), --和lastCommittedOpTime關聯
"readConcernMajorityOpTime" : { -- 完成讀取操作的最新操作的資訊涉及“多數”查詢
"ts" : Timestamp(1597285472, 1),
"t" : NumberLong(1)
},
"readConcernMajorityWallTime" : ISODate("2020-08-13T02:24:32.634Z"), --和readConcernMajorityOpTime關聯
"appliedOpTime" : { -- 應用于副本集此成員的最新操作的資訊
"ts" : Timestamp(1597285472, 1),
"t" : NumberLong(1)
},
"durableOpTime" : { -- 寫入副本集此成員的日記中的最新操作的資訊
"ts" : Timestamp(1597285472, 1),
"t" : NumberLong(1)
},
"lastAppliedWallTime" : ISODate("2020-08-13T02:24:32.634Z"), --和appliedOpTime關聯
"lastDurableWallTime" : ISODate("2020-08-13T02:24:32.634Z") --和durableOpTime關聯
},
"lastStableRecoveryTimestamp" : Timestamp(1597285442, 1),
"lastStableCheckpointTimestamp" : Timestamp(1597285442, 1), -- 4.2版起棄用,适用于WiredTiger存儲引擎,目前或上一個持久檢查點所在的時間戳
"electionCandidateMetrics" : { -- 與選舉相關的名額。 隻有在主要候選人或候選人身上,才可以使用競選候選人資格名額。 對于候選人,一旦候選人失去選舉,該名額将不可用。
"lastElectionReason" : "electionTimeout", -- 該成員召集了選舉
"lastElectionDate" : ISODate("2020-08-13T01:32:02.522Z"), -- 選舉的日期和時間
"electionTerm" : NumberLong(1), -- 該成員要求進行新選舉時的選舉計數(即任期)
"lastCommittedOpTimeAtElection" : { -- 最近一次多數派承諾的optime要求進行新的選舉
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"lastSeenOpTimeAtElection" : { -- 該成員在要求進行新選舉時最近一次使用optime
"ts" : Timestamp(1597282312, 1),
"t" : NumberLong(-1)
},
"numVotesNeeded" : 2, -- 赢得選舉所需的票數
"priorityAtElection" : 1, -- 成員在進行選舉時的優先級
"electionTimeoutMillis" : NumberLong(10000), --成員選舉的逾時時間,機關毫秒,預設10s。
"numCatchUpOps" : NumberLong(0), -- 新當選的主其追趕過程時所應用的操作數
"newTermStartDate" : ISODate("2020-08-13T01:32:02.560Z"), -- 新任期條目寫入記錄檔的日期和時間
"wMajorityWriteAvailabilityDate" : ISODate("2020-08-13T01:32:02.703Z") --選擇副本集後,可以使用寫關注點“多數”的日期和時間(即,新任期oplog條目被送出了多數的日期和時間)。
},
"members" : [ -- 副本集中每個成員的文檔
{
"_id" : 0, -- 成員的辨別符
"name" : "11.11.11.11:27017", --成員的名稱
"health" : 1, -- 成員是否存活
"state" : 1, -- 0到10之間的整數,表示成員的副本狀态,https://docs.mongodb.com/manual/reference/replica-states/
"stateStr" : "PRIMARY", -- 描述狀态的字元串
"uptime" : 5203, -- 運作時間
"optime" : { -- 應用的記錄檔中有關最後操作的資訊
"ts" : Timestamp(1597285472, 1), -- 記錄檔中應用于副本集的此成員的最後一個操作的時間戳。
"t" : NumberLong(1) -- 最後一次應用的操作次數
},
"optimeDate" : ISODate("2020-08-13T02:24:32Z"), -- 記錄檔中的最後一個記錄。 如果與lastHeartbeat明顯不同,則該成員正在經曆“複制滞後”,或者自上次更新以來沒有任何新操作。
"syncingTo" : "", -- 同步的成員的ip
"syncSourceHost" : "", -- 同步的成員的主機名,如果成員是Primary,則顯示空格
"syncSourceId" : -1, -- 如果成員是Primary,則顯示-1,否則顯示對應的member._id
"infoMessage" : "", -- 複制集資訊
"electionTime" : Timestamp(1597282322, 1), -- 對于目前主資料庫,有關記錄檔中選舉時間戳
"electionDate" : ISODate("2020-08-13T01:32:02Z"), -- 對于目前主資料庫,有關記錄檔中選舉時間
"configVersion" : 1, -- 副本集配置版本
"self" : true, -- 是否為目前mongod執行個體
"lastHeartbeatMessage" : "" -- 當最後一個心跳包括額外的消息時,lastHeartbeatMessage将包含該消息的字元串表示形式。
},
{
"_id" : 1,
"name" : "11.11.22.22:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 3166,
"optime" : {
"ts" : Timestamp(1597285472, 1),
"t" : NumberLong(1)
},
"optimeDurable" : { -- 對其日記(journal)應用的記錄檔中有關最後操作的資訊
"ts" : Timestamp(1597285472, 1), -- 操作的時間戳
"t" : NumberLong(1) -- 生産的操作次數
},
"optimeDate" : ISODate("2020-08-13T02:24:32Z"),
"optimeDurableDate" : ISODate("2020-08-13T02:24:32Z"),
"lastHeartbeat" : ISODate("2020-08-13T02:24:36.549Z"), -- 最後一次收到心跳的響應并發送給成員。将此值與date和lastHeartBeatRecv字段的值進行比較,以跟蹤這些副本內建員之間的延遲。
"lastHeartbeatRecv" : ISODate("2020-08-13T02:24:38.071Z"), -- 同上
"pingMs" : NumberLong(0), -- 表示往返資料包在遠端成員和本地執行個體之間傳播所需的毫秒數。
"lastHeartbeatMessage" : "",
"syncingTo" : "11.11.22.23:27017",
"syncSourceHost" : "11.11.22.23:27017",
"syncSourceId" : 2,
"infoMessage" : "",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "11.11.22.23:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 3166,
"optime" : {
"ts" : Timestamp(1597285472, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1597285472, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2020-08-13T02:24:32Z"),
"optimeDurableDate" : ISODate("2020-08-13T02:24:32Z"),
"lastHeartbeat" : ISODate("2020-08-13T02:24:36.591Z"),
"lastHeartbeatRecv" : ISODate("2020-08-13T02:24:37.162Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "11.11.11.11:27017",
"syncSourceHost" : "11.11.11.11:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
}
],
"ok" : 1, -- 是否執行成
"$clusterTime" : {
"clusterTime" : Timestamp(1597285472, 1),
"signature" : {
"hash" : BinData(0,"lbLV7xyYk7NJHtg6EFD/E7Jy+dE="),
"keyId" : NumberLong("6860275335468941315")
}
},
"operationTime" : Timestamp(1597285472, 1) -- 指令執行時間
}
rs.slave
Ok
() :允許對從節點執行讀取操作。
8. 維護模式,啟用或禁用副本集從節點的維護模式,之後會進入RECOVERING狀态:replSetMaintenance。必須在從節點上的admin資料庫下執行。
進入維護模式:
shard1:SECONDARY> db.adminCommand({"replSetMaintenance":true})
{ "ok" : 1 }
shard1:RECOVERING>
RECOVERING狀态的成員能複制,但是不允許讀,可以用隐藏節點來替換該模式。
退出維護模式:
shard1:RECOVERING> db.adminCommand({"replSetMaintenance":false})
{ "ok" : 1 }
shard1:SECONDARY>
9. OpLog大小設定:replSetResizeOplog:動态調整,size參數以M為機關,而OpLog的大小以位元組為機關。隻能在與Wired Tiger存儲引擎一起運作,減小記錄檔的大小不會自動回收該磁盤空間。
db.adminCommand({replSetResizeOplog:1, size: 16384})
MongoDB 3.4和更早版本中,通過删除并重新建立local.oplog.rs集合來調整記錄檔的大小,具體的操作可以看 MongoDB的oplogSize修改。
MongoDB 3.6及更高版本中,請使用replSetResizeOplog指令來調整記錄檔的大小。從MongoDB 4.0開始,MongoDB禁止drop local.oplog.rs集合。從Secondary成員開始,然後再進行Primary操作。
① 檢視目前OpLog大小:
shard1:SECONDARY> use local
switched to db local
shard1:SECONDARY> db.oplog.rs.stats().maxSize
104857600 -- 100M
②:修改OpLog大小:
shard1:SECONDARY> db.adminCommand({replSetResizeOplog: 1, size: 1000})
{ "ok" : 1 }
shard1:SECONDARY> db.oplog.rs.stats().maxSize
1048576000 -- 1000M
在從節點上執行完之後,再去主節點上執行(先rs.stepDown)。
注意:對于MongoDB 4.2.2和更高版本,replSetResizeOplog在記錄檔上獲得排他(W)鎖,并阻止對集合的其他操作,直到完成。對于MongoDB 4.2.1和更早版本,replSetResizeOplog采用全局排他(W)鎖定并阻止所有其他操作,直到完成。
10. 回收磁盤空間,壓縮oplog.rs以回收磁盤空間,減小oplog的大小不會回收已經配置設定的磁盤空間,必須壓縮oplog.rs來回收磁盤空間:
use local
db.runCommand({"compact" : "oplog.rs"})
注意:當執行壓縮時,從節點無法複制oplog條目,會導緻主節點的記錄檔被覆寫,導緻節點無法同步資料而産生重新完全同步,建議在無業務的時間段内執行壓縮操作。
11. settings的設定:settings
rs.config().settings:修改副本集的一些設定,可以看上面的rs.conf()說明:
- chainingAllowed:預設ture。隻有true才能使用參數
initialSyncSourceReadPreference
當settings.chainingAllowed為true時,副本集允許輔助成員從其他輔助成員進行複制(鍊式複制)。 當settings.chainingAllowed為false時,輔助節點隻能從主節點複制。
- heartbeatIntervalMillis:預設2000
各個副本間的心跳間隔,機關毫秒,預設2秒。
- heartbeatTimeoutSecs:預設10秒
副本內建員等待彼此成功發出心跳的秒數。 如果某個成員未及時響應,則其他成員會将該成員标記為不可通路。
- electionTimeoutMillis:預設1000毫秒,即10秒
檢測副本集主庫不可用的時間限制(以毫秒為機關),較高的值會導緻較慢的故障轉移,會降低對主節點或網絡的速度的敏感度。 較低的值将導緻更快的故障轉移,會增加對主節點或網絡的速度的敏感性。 在版本4.0.2中:如果參數enableElectionHandoff為true(預設值),則當主節點從rs.stepDown降級時,已降級的主節點将指定合格的輔助節點立即選舉。否則,輔助節點在調用選舉之前先等待settings.electionTimeoutMillis。
- catchUpTimeoutMillis:機關毫秒,預設-1,不限制追趕時間。
新選擇的主資料庫與其他可能具有更近期寫入操作的副本內建員同步(追趕)的時間限制(以毫秒為機關)。無限或高時間限制可能會減少選舉後其他成員需要復原的資料量,但可能會增加故障轉移時間。 一旦新當選的主要成員完全趕上集合中的其他成員,他們就會提前結束趕超階段。在追趕期間,新選擇的主伺服器不可用于來自用戶端的寫入。使用replSetAbortPrimaryCatchUp中止追趕,然後完成向主要角色的過渡。
- catchUpTakeoverDelayMillis:預設30000毫秒,即30秒
接管的節點确定它在目前主節點之前,然後等待指定的毫秒數,發起選舉。選舉驗證以下内容: 它仍然領先于目前的主要資料庫, 它是所有可用節點中最新的節點, 目前的主資料庫正在趕上它。 一旦确定滿足所有這些條件,發起接管的節點将立即運作以進行選舉。
-
getLastErrorModes:通過使用member[n].tags自定義寫關注點的文檔,定制寫關注點可以提供資料中心的概念。
格式:
<number>是指滿足寫關注所需的不同标簽值的數量。 例如,以下settings.getLastErrorModes定義了一個名為datacenter的寫關注點,該寫關注點要求該寫傳播到dc tag不同的兩個成員:{ getLastErrorModes: { <name of write concern> : { <tag1>: <number>, .... }, ... } }
要使用自定義寫關注點,請将寫關注點名稱傳遞給w選項:{ getLastErrorModes: { datacenter: { "dc": 2 } } }
tag的設定就在member[n].tags中定義,即副本內建員中的屬性。如何配置tags請看文檔說明:{ w: "datacenter" }
db.collection.insert( { id: "xyz", status: "A" }, { writeConcern: { w: "datacenter" } } )
- getLastErrorDefaults
指定副本集寫關注點的文檔。 僅當寫入操作或getLastError沒有指定其他寫入時,副本集才會使用此寫關注。 如果未設定settings.getLastErrorDefaults,則副本集的預設寫關注點僅需要主資料庫的确認。{"w" : 1},如: db..insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 4 , wtimeout: 5000 } } ) 如果數量不足4個,則會報錯:Not enough data-bearing nodes
- replicaSetId
與副本集關聯并在rs.initiate()或replSetInitate期間自動建立的ObjectId
local資料庫:
local資料庫:
MongoDB執行個體都有其自己的本地資料庫,副本集中各個成員的複制資料時都是把local資料庫排除在外,将其他資料庫的資料複制到自己的資料庫中。關于local的資料庫介紹可以看文檔。現在來看下local資料庫下存的是哪些集合:
①
local.
startup_log:startup_log是一個capped文檔,記錄執行個體啟動的一些診斷資訊

> db.startup_log.find().pretty()
{
"_id" : "test4-1614219412340",
"hostname" : "test4",
"startTime" : ISODate("2021-02-25T02:16:52Z"),
"startTimeLocal" : "Thu Feb 25 02:16:52.340",
"cmdLine" : {
"config" : "/usr/local/mongodb_2/mongo.conf",
"net" : {
"bindIp" : "0.0.0.0",
"maxIncomingConnections" : 65536,
"port" : 27018,
"unixDomainSocket" : {
"enabled" : true,
"filePermissions" : 448,
"pathPrefix" : "/tmp"
},
"wireObjectCheck" : true
},
"operationProfiling" : {
"mode" : "slowOp",
"slowOpSampleRate" : 1,
"slowOpThresholdMs" : 100
},
"processManagement" : {
"fork" : true,
"pidFilePath" : "/usr/local/mongodb_2/mongodb.pid"
},
"replication" : {
"enableMajorityReadConcern" : false,
"oplogSizeMB" : 100,
"replSetName" : "shard1"
},
"security" : {
"authorization" : "enabled",
"keyFile" : "/usr/local/mongodb_2/xx_keyfile"
},
"sharding" : {
"archiveMovedChunks" : false,
"clusterRole" : "shardsvr"
},
"storage" : {
"dbPath" : "/usr/local/mongodb_2/data",
"directoryPerDB" : true,
"engine" : "wiredTiger",
"journal" : {
"commitIntervalMs" : 500,
"enabled" : true
},
"syncPeriodSecs" : 60,
"wiredTiger" : {
"collectionConfig" : {
"blockCompressor" : "snappy"
},
"engineConfig" : {
"cacheSizeGB" : 1,
"directoryForIndexes" : false,
"journalCompressor" : "snappy",
"maxCacheOverflowFileSizeGB" : 0
},
"indexConfig" : {
"prefixCompression" : true
}
}
},
"systemLog" : {
"destination" : "file",
"logAppend" : true,
"logRotate" : "rename",
"path" : "/usr/local/mongodb_2/logs/mongodb.log",
"quiet" : false,
"timeStampFormat" : "iso8601-local",
"traceAllExceptions" : false,
"verbosity" : 0
}
},
"pid" : NumberLong(70856),
"buildinfo" : {
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f",
"modules" : [ ],
"allocator" : "tcmalloc",
"javascriptEngine" : "mozjs",
"sysInfo" : "deprecated",
"versionArray" : [
4,
2,
8,
0
],
"openssl" : {
"running" : "OpenSSL 1.1.1 11 Sep 2018",
"compiled" : "OpenSSL 1.1.1 11 Sep 2018"
},
"buildEnvironment" : {
"distmod" : "ubuntu1804",
"distarch" : "x86_64",
"cc" : "/opt/mongodbtoolchain/v3/bin/gcc: gcc (GCC) 8.2.0",
"ccflags" : "-fno-omit-frame-pointer -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -O2 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -Wno-unused-const-variable -Wno-unused-but-set-variable -Wno-missing-braces -fstack-protector-strong -fno-builtin-memcmp",
"cxx" : "/opt/mongodbtoolchain/v3/bin/g++: g++ (GCC) 8.2.0",
"cxxflags" : "-Woverloaded-virtual -Wno-maybe-uninitialized -fsized-deallocation -std=c++17",
"linkflags" : "-pthread -Wl,-z,now -rdynamic -Wl,--fatal-warnings -fstack-protector-strong -fuse-ld=gold -Wl,--build-id -Wl,--hash-style=gnu -Wl,-z,noexecstack -Wl,--warn-execstack -Wl,-z,relro",
"target_arch" : "x86_64",
"target_os" : "linux"
},
"bits" : 64,
"debug" : false,
"maxBsonObjectSize" : 16777216,
"storageEngines" : [
"biggie",
"devnull",
"ephemeralForTest",
"wiredTiger"
]
}
}
②
local.system.
replset:副本集的配置資訊,資訊和rs.conf()輸出一樣
③
local.oplog.
rs:用來儲存oplog的capped集合,類似于MySQL的Binlog
④
local.replset.
minvalid:副本集在内部使用該集合來跟蹤複制狀态
複制集讀寫:
關于标簽集(tags set)的讀寫方式可以看官網例子
1. 讀
① 讀首選項:Read Preference :控制用戶端 Driver API 從複制集的哪個節點讀取資料,友善的實作讀寫分離、就近讀取等政策。預設讀主節點。政策有:
-
隻從 primary 節點讀資料(預設設定),和使用tag或maxStalenessSeconds的模式不相容。primary:
-
優先從 primary 讀取,primary 不可服務,從 secondary 讀:primaryPreferred:
-
隻從 scondary 節點讀資料。secondary:
-
優先從 secondary 讀取,沒有 secondary 成員時,從 primary 讀取。secondaryPreferred:
-
根據網絡距離就近讀取,距離最近的成員不超過15毫秒。nearest:
注意:讀取操作多文檔事務必須使用primary模式,給定事務中的所有操作都必須路由到同一成員。除primary外,其他模式可以包含 maxStalenessSeconds 和 tag sets :
- 當包含maxStalenessSeconds值時,會對比主和從的延遲是否大于該值,小于則直接從節點讀取,該值需要大于90秒。
- 當包含 tag sets 時,會在比對标簽的從上進行讀取。可以在副本內建員的屬性中修改tag。具體的使用可以看文檔說明。
- 當包含maxStalenessSeconds和 tag set 時,先根據資料的延遲maxStalenessSeconds過濾,再根據tag set讀取。
從地理分布的成員進行查詢
如果副本集的成員在地理位置上分散,則可以基于副本集标記來反映執行個體的位置,然後将應用程式配置為查詢附近的成員。如,如果“東部”和“西部”資料中心中的成員被标記為{'dc':'east'}和{'dc':'west'},則東部資料中心中的應用程式伺服器可以從附近的成員中讀取 具有以下讀取首選項:
> db.collection.find().readPref('nearest', [ { 'dc': 'east' } ])
除primary模式外,其他模式都可能傳回陳舊資料,因為輔助資料庫在異步過程中從主資料庫複制操作。雖然可以通過maxStalenessSeconds來控制延遲。但可以配合 read concern 使用來解決延遲導的問題。
② 讀關注:Read Concern:通過寫入關注點和讀取關注點,控制從副本集和副本集分片讀取的資料的一緻性和隔離性。決定到某個讀取資料時,能讀到什麼樣的資料。
-
"local":該查詢從執行個體傳回資料,但不能保證該資料已被寫入大多數副本內建員(即可以復原),預設。
-
"available":該查詢從執行個體傳回資料,但不能保證該資料已被寫入大多數副本內建員(即可以復原)。
-
"majority":該查詢傳回大多數副本內建員已确認的資料。即使發生故障也很不影響。副本集必須使用WiredTiger存儲引擎。對于具有三名成員的主從仲裁器(PSA)架構的部署,可以禁用“讀取關注”的“多數”功能。對于多文檔事務中的操作,僅當事務以write Concern “多數”送出時,Read Concern “多數”才提供其保證。否則,“多數”讀取問題不能保證事務中讀取的資料。
-
"linearizable":該查詢傳回的資料反映了在讀取操作開始之前完成的所有成功的多數确認寫入。在傳回結果之前,查詢可以等待并發執行的寫入傳播到大多數副本內建員。 writeConcernMajorityJournalDefault為true(預設):持久,不丢失復原 writeConcernMajorityJournalDefault為false:可能丢失復原
-
"snapshot":僅可用于多文檔事務。
readPreference
和
readConcern
可以配合使用。
readConcern 解決什麼問題
readConcern
的初衷在于解決『髒讀』的問題,比如使用者從 MongoDB 的 primary 上讀取了某一條資料,但這條資料并沒有同步到大多數節點,然後 primary 就故障了,重新恢複後 這個primary 節點會将未同步到大多數節點的資料復原掉,導緻使用者讀到了『髒資料』。
當指定 readConcern 級别為 majority 時,能保證使用者讀到的資料『已經寫入到大多數節點』,而這樣的資料肯定不會發生復原,避免了髒讀的問題。
需要注意的是,
readConcern
能保證讀到的資料『不會發生復原』,但并不能保證讀到的資料是最新的,這個官網上也有說明。
有使用者誤以為,
readConcern
指定為 majority 時,用戶端會從大多數的節點讀取資料,然後傳回最新的資料。
實際上并不是這樣,無論何種級别的
readConcern
,用戶端都隻會從『某一個确定的節點』(具體是哪個節點由 readPreference 決定)讀取資料,該節點根據自己看到的同步狀态視圖,隻會傳回已經同步到大多數節點的資料。
readConcern 實作原理:
MongoDB 要支援 majority 的 readConcern 級别,必須設定
replication.enableMajorityReadConcern
參數,加上這個參數後,MongoDB 會起一個單獨的snapshot 線程,會周期性的對目前的資料集進行 snapshot,并記錄 snapshot 時最新 oplog的時間戳,得到一個映射表。
最新 oplog 時間戳 | snapshot | 狀态 |
---|---|---|
t0 | snapshot0 | committed |
t1 | snapshot1 | uncommitted |
t2 | snapshot2 | |
t3 | snapshot3 |
隻有確定 oplog 已經同步到大多數節點時,對應的 snapshot 才會标記為 commmited,使用者讀取時,從最新的 commited 狀态的 snapshot 讀取資料,就能保證讀到的資料一定已經同步到的大多數節點。
關鍵的問題就是如何确定『oplog 已經同步到大多數節點』?
primary 節點
secondary 節點在自身oplog發生變化時,會通過 replSetUpdatePosition 指令來将 oplog 進度立即通知給 primary,另外心跳的消息裡也會包含最新 oplog 的資訊;通過上述方式,primary 節點能很快知道 oplog 同步情況,知道『最新一條已經同步到大多數節點的 oplog』,并更新 snapshot 的狀态。比如當t2已經寫入到大多資料節點時,snapshot1、snapshot2都可以更新為 commited 狀态。(不必要的 snapshot也會定期被清理掉)
secondary 節點
secondary 節點拉取 oplog 時,primary 節點會将『最新一條已經同步到大多數節點的 oplog』的資訊傳回給 secondary 節點,secondary 節點通過這個oplog時間戳來更新自身的 snapshot 狀态。
注意:
- 目前
主要用于 mongos 與 config server 的互動上readConcern
- 使用
需要配置readConcern
選項replication.enableMajorityReadConcern
- 隻有支援 readCommited 隔離級别的存儲引擎才能支援
,比如 wiredtiger 引擎。readConcern
2. 寫
寫關注:Write Concern :MongoDB請求對獨立mongod或副本集或分片叢集的寫操作的确認級别。 在分片叢集中,mongos執行個體會将寫關注事項傳遞給分片。
4.4開始,副本集和分片群集支援設定全局預設寫入,未指定顯式寫關注點的操作将繼承全局預設寫關注點設定
格式:可以在指令行裡指定,也可以修改settings裡的預設模式來修改。
{ w: <value>, j: <boolean>, wtimeout: <number> }
- w:請求确認寫入操作已傳播到指定數量的mongod執行個體或具有指定标簽的mongod執行個體,如果執行個體不足,則寫入報錯。
- j:請求确認已将寫操作寫入磁盤日志中。
- wtimeout:指定一個時間限制,以防止無限期地阻止寫操作。
w:
value | 含義 |
num | 1:是MongoDB的預設寫關注點,寫自身Primary節點。可復原; 0:不要求确認寫入操作。但可能會将有關套接字異常和網絡錯誤的資訊傳回給應用程式。可復原。 >1:需要>1個節點确認,比如3,則需要1Primary和2Secondary确認。 注意:Hidden, delayed, and priority 0的節點可以确認 副本集的任何帶有資料的投票成員都可以對“多數”寫操作進行寫确認。 |
majority | 請求确認寫入操作已傳播到所計算的大多數帶有資料的投票成員(具有投票屬性)。 比如P-S-S架構,需要寫入P和一個S |
自定義寫關注名 | 請求确認寫操作已傳播到滿足settings.getLastErrorModes中定義的自定義寫關注點的标記成員。 |
j:
value | |
true | true: 請求确認已将w:<value>中指定的mongod執行個體寫入磁盤日志中。僅在請求數量的成員(包括主要成員)寫入日志後才傳回,副本集中表現為需要将操作寫入磁盤日志 |
false | false:不需要确認寫入。副本集中表現為需要将操作寫入記憶體 |
wtimeout:
指定寫關注的時間限制(以毫秒為機關)。 wtimeout僅适用于大于1的w值。如果寫操作超過指定時間之後則傳回錯誤,即使最終成功完成了必需的寫操作。 當這些寫操作傳回時,MongoDB不會撤消在寫關注超出wtimeout時間限制之前執行的成功資料修改。如果未指定wtimeout選項(0),并且無法達到寫關注級别,則寫操作将無限期阻塞。 例:

-- 在P-S-S架構中,摸一個S當機,需要寫入3個節點
XYZ:PRIMARY> db.xx.insert({"aaa":3},{writeConcern:{w:3 ,j:true , wtimeout:5000 }})
WriteResult({
"nInserted" : 1,
"writeConcernError" : {
"code" : 64,
"codeName" : "WriteConcernFailed",
"errmsg" : "waiting for replication timed out",
"errInfo" : {
"wtimeout" : true
}
}
})
-- 需要寫入2個節點
XYZ:PRIMARY> db.xx.insert({"aaa":3},{writeConcern:{w:2 ,j:true , wtimeout:5000 }})
WriteResult({ "nInserted" : 1 })
-- 副本集包含3個有投票權的成員(P-S-S):
所有投票成員中大多數為2。
所有有資料投票的成員人數為3。
多數為2,最小值為2和3。寫入必須傳播到主和一個從,以向用戶端确認寫入關注“多數”。
-- 副本集包含3個投票成員,主要-次要仲裁員(P-S-A)
所有投票成員中大多數為2。
所有有資料投票的成員人數為2。
計算得出的多數為2,最小值為2和2。由于該寫操作隻能應用于資料承載成員,是以該寫操作必須傳播到主和從,以向用戶端确認寫關注點“多數”。
避免對(P-S-A)或其他拓撲使用 majority write concern 問題,以為一個從節點失效之後,寫入就失敗了。使用 majority write concern方式來保證持久性的應改用不要求所有具有資料投票權的成員都可用的拓撲(例如P-S-S)。
參數設定:
參數除了在配置檔案中設定外,部分動态參數也可以直接在指令行裡修改。
① 檢視參數:getParameter
用于在指令行上檢視參數,必須在admin資料庫下執行,并以以下形式對管理資料庫發出setParameter指令:
db.adminCommand( { getParameter : 1, <parameter> : <value> } )
檢視指定參數saslHostName的值:
> db.adminCommand( { getParameter : 1, "saslHostName" : 1 } )
{ "saslHostName" : "test4", "ok" : 1 }
檢視所有參數:
db.adminCommand( { getParameter : '*' } )
② 修改參數:setParameter
用于在指令行上修改參數,必須在admin資料庫下執行,以以下形式對管理資料庫發出setParameter指令:
db.adminCommand( { setParameter: 1, <parameter> : <value> } )
對應在配置檔案中的為:
setParameter:
<parameter1>: <value1>
對應指令行啟動的為:
mongod --setParameter <parameter>=<value>
mongos --setParameter <parameter>=<value>
修改指定參數:logLevel
> db.adminCommand( { setParameter: 1, logLevel: 2 } )
關于其他一些可修改的參數,可以看:伺服器可調參數
參考文檔:
Replication
Replication Methods
Replication Commands
MongoDB 副本集的原理、搭建、應用
MongoDB 副本集管理
~~~~~~~~~~~~~~~
萬物之中,希望至美
~~~~~~~~~~~~~~~