Procedure
Run the following command on any node in the cluster:
zbs-node mongo status
Output example
{
"$clusterTime": {
"clusterTime": {
"$timestamp": {
"i": 164,
"t": 1668590597
}
},
"signature": {
"hash": {
"$binary": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"$type": "00"
},
"keyId": 0
}
},
"date": {
"$date": 1668590597686
},
"electionCandidateMetrics": {
"electionTerm": 1,
"electionTimeoutMillis": 10000,
"lastCommittedOpTimeAtElection": {
"t": -1,
"ts": {
"$timestamp": {
"i": 1,
"t": 1668587490
}
}
},
"lastElectionDate": {
"$date": 1668587502162
},
"lastElectionReason": "electionTimeout",
"lastSeenOpTimeAtElection": {
"t": -1,
"ts": {
"$timestamp": {
"i": 1,
"t": 1668587490
}
}
},
...
}Output note
Check whether the MongoDB service is running normally using the following output parameters.
not reachable/health: The MongoDB service of this node is abnormal.PRIMARY: The node's role is primary, and the MongoDB service is running normally.SECONDARY: The node's role is secondary, and the MongoDB service is running normally.Procedure
Run the following command on any node in the cluster:
zbs-node mongo list
Output example
10.0.0.11:27017
10.0.0.13:27017
10.0.0.14:27017Procedure
Run the following command on any node in the cluster:
zbs-node mongo leader
Output example
10.0.0.11:27017Procedure
On nodes running the mongod service in the cluster, run the following command to enter the MongoDB Shell to perform queries or maintenance. This command is equivalent to the mongo or mongosh command officially provided by MongoDB.
zbs-node mongo shell
Output example
MongoDB shell version v5.0.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("75e9a2c2-d8ab-4f12-b5b1-fcfab66d06db") }
MongoDB server version: 5.0.6
================
Warning: the "mongo" shell has been superseded by "mongosh",
which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in
an upcoming release.
For installation instructions, see
https://docs.mongodb.com/mongodb-shell/install/
================
---
The server generated these startup warnings when booting:
2022-11-16T16:30:25.280+08:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2022-11-16T16:30:25.972+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2022-11-16T16:30:25.972+08:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleave=all mongod [other options]
---
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
zbs:SECONDARY>When a Mongo node enters the recovering state due to a data directory issue or losing synchronization with the Mongo primary node, you can use this command to clear the node's Mongo data directory (/var/lib/mongodb) and restart the mongod service on this node to resynchronize data with other nodes and restore normal status.
Procedure
Run the following command on the Mongo node that needs to be resynchronized:
zbs-node mongo resync
Output example
All mongo data on this node will be cleared
Are you sure to continue? [y/N]: y
2024-12-24 14:36:47,317 node.py 1296 [53562] [INFO] pre-check success, mongod is ready to resync
2024-12-24 14:36:47,317 recovering_resync.py 169 [53562] [INFO] starting rescue mongod ...
2024-12-24 14:36:47,317 recovering_resync.py 74 [53562] [INFO] stopping mongod.service ...
2024-12-24 14:36:47,333 recovering_resync.py 78 [53562] [INFO] cmd: systemctl status mongod res: 0 output: ● mongod.service - containerd mongod.service
...
2024-12-24 14:36:47,334 recovering_resync.py 83 [53562] [INFO] systemctl stop mongod
2024-12-24 14:37:03,889 recovering_resync.py 85 [53562] [INFO] cmd: systemctl stop mongod res: 0 output:
2024-12-24 14:37:03,916 recovering_resync.py 93 [53562] [INFO] cmd: systemctl status mongod res: 3 output: ● mongod.service - containerd mongod.service
...
2024-12-24 14:37:03,917 recovering_resync.py 130 [53562] [INFO] cleaning /var/lib/mongodb/ ...
2024-12-24 14:37:03,924 recovering_resync.py 142 [53562] [INFO] clean data files: /var/lib/mongodb/collection-412-6983241241505598203.wt
...
2024-12-24 14:37:04,020 recovering_resync.py 142 [53562] [INFO] clean data files: /var/lib/mongodb/index-304-6983241241505598203.wt
2024-12-24 14:37:04,020 recovering_resync.py 98 [53562] [INFO] restarting mongod.service ...
2024-12-24 14:37:04,047 recovering_resync.py 102 [53562] [INFO] cmd: systemctl status mongod res: 3 output: ● mongod.service - containerd mongod.service
...
2024-12-24 14:37:04,047 recovering_resync.py 107 [53562] [INFO] systemctl restart mongod
2024-12-24 14:37:04,136 recovering_resync.py 109 [53562] [INFO] cmd: systemctl restart mongod res: 0 output:
2024-12-24 14:37:04,150 recovering_resync.py 117 [53562] [INFO] cmd: systemctl status mongod res: 0 output: ● mongod.service - containerd mongod.service
...
2024-12-24 14:37:04,150 recovering_resync.py 158 [53562] [INFO] check mongo rs.status(), round 0
2024-12-24 14:37:04,153 recovering_resync.py 164 [53562] [INFO] wait for mongo recovery: (not reachable/healthy)
2024-12-24 14:37:14,155 recovering_resync.py 158 [53562] [INFO] check mongo rs.status(), round 1
2024-12-24 14:37:14,157 recovering_resync.py 161 [53562] [INFO] mongo state become healthy: SECONDARY
2024-12-24 14:37:14,157 node.py 1298 [53562] [INFO] resync mongod data succeed