Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mongodb replica set maintenance

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

I. Overview

The main tasks of mongodb replica set maintenance are as follows:

1. Check the replica set status (cluster status, synchronization delay, mongostate of a single library)

2. Add and delete nodes and stop nodes shutdown

Mongodb replica set Cluster synchronization Mechanism

The purpose of data replication is to maximize data availability, redundancy and avoid a single point of failure.

Only one server in the replica set can be written at a time. It is written on the primary main library and synchronizes data from the database.

Master-slave replication of replica sets is also an asynchronous synchronization process. Slave takes logs from primary and performs logging operations on itself in full order (the log does not record query operations, only update operations). The log being synchronized is the oplog.rs table in the local library, which takes up a large amount of space and has a disk size of 5%. The startup parameter sets the size of the oplog.rs:-- oplogSize 1000, in M. A larger setting is recommended in the production environment to prevent the occurrence of unsynchronized conditions.

Second, check the cluster status

1.rs.status ()

2.db.printSlaveReplicationInfo ()

View master-slave database delay time

3.mongodb Monitoring tool-mongostat

3.1 if you find that DB suddenly slows down or has other problems, first check the status by mongostat

Mongostat-uxx-pyy-rowcount 12 300mongostat-uxx-pyy-N 12300 # # outputs DB status every 300 seconds for a total of 12 times

3.2 description of output parameters

Inserts/s inserts per second

Number of queries per second by query/s

Update/s updates per second

Number of delete/s deletions per second

Getmore/s executes getmore times per second. When querying, the getmore operation of cursor is of little use.

Command/s commands per second, more than the above insert, find, update, delete, but also includes other commands. For example, batch insertion, only one command, does not make much sense.

The number of times per second that flushes/s executes fsync to write data to disk. It is usually 0 and 1 when brushing the disk. You can judge how often the data is refreshed to the disk by the interval between the two ones. Flush is very expensive, if the stock is refreshed frequently, there may be problems.

The amount of data that is nmap in mapped/s, in MB.

Vsize virtual memory usage (in MB)

Res physical memory usage (in MB). This is the same as the state seen by top, mapped/vsize generally does not change much, res will rise slowly, if res often drops suddenly, check to see if there are other programs eating memory.

The number of faults/s access failures per second (only linux has). Data is swapped out of physical memory and put into swap. If it is often not 0, the server memory is too small, resulting in frequent swap writes. Increase the memory at this time.

The percentage of time that locked db% is locked up should be kept below 50% as far as possible. This value is too large (often more than 10%, there may be a problem)

Idx miss% very important parameter, the percentage of index misses. Normally, queries should pass through the index, that is, idx miss is 0. If it is too high, there are too few indexes.

Qr | qw queue lengths for clients waiting (read | write) the length of read and write requests from the client.

Ar | aw active clients (read | write) read and write requests from active clients. That is, the total read and write requests.

PS: when mongdb receives too many commands and the database is locked and cannot be executed, commands are added to the queue. All 0 means that there is no pressure on the mongodb. When the concurrency is high, the queue value will increase, indicating that the processing speed of the DB is not as fast as the request speed. See if there are expensive slow queries. If the query is all right and the load is really heavy, consider adding a server.

Net In/Out network bandwidth pressure, the general network will not become the bottleneck of mongdb.

Current number of connections to conn

Set replica set cluster name

The status of repl's current library in the cluster. PRI-master,SEC-second,REC-recovering,UNK-unkown

Time timestamp

4.web console

Mongodb comes with the web console, which is enabled by default with the data service. Default port 28017 (+ 1000 based on data port 27017)

The status page displays information:

4.1 all connections to the current db

4.2 access statistics for each database dbs and collection, including reads/writes/queries/getmores/inserts/updates/removes

4.3 write status of the lock

4.4 the last few hundred lines of the log file

4.5 other commands for mongodb status query on the top two lines

5. Gets the operation db.currentOp () that mongodb is currently performing

> db.currentOp () > {"opid": "shard3:466404288", "active": false, "waitingForLock": false, "op": "query", "ns": "sd.usersEmails", "query": {}, "client_s": "10.121.13.8 false", "desc": "conn"}

5.1 Kill commands that have been executed for too long

> db.killOp ("shard3:466404288")

6.MongoDB Monitoring Service MongoDB Monitoring Service (MMS)

Monitoring services provided by mongodb vendors, which can be viewed on web pages and Andriod clients

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report