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 big data operation and maintenance management

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Database management

Back up the MONGODB server

Execute mongodump / / use local connection 127 and port to connect to local database by default

The database is restored to the state it was before the backup:

Mongorestore-drop

# #-the drop option tells the mongorestore tool to discard existing data before restoring the collection. If this option is not used, the recovered data will be appended to the tail of each collection, resulting in data duplication

Back up a single database

Mongodump-d database_name-c post # # backup collections under the specified library

-- help

Restore a single database

Mongorestore-d blog-- drop

Restore a single collection

Mongorestore-d blog-c posts-- drop

Back up a large database

The database backup system has a must-kill skill, that is, point-in-time snapshots, which is very fast. The faster the snapshot is completed, the shorter the time it takes for the database server to be frozen.

It is very easy to create a hidden secondary server in MONGODB, and you can use MONGODB's replication mechanism to ensure that it is always with the primary server.

1 create a snapshot using the journaling file system

2 backup data using a hidden secondary server

Execute fysnc and lock on MONGODB to ensure that the mirroring of the database on disk is consistent and that they remain consistent until the snapshot is completed

Use admin

Db.fsyncLock () / / enter fsync and lock status

View the status of the current lock

Use admin

Db.currentOp ()

Release lock

Db.fsyncUnlock () / / there may be a short delay before the lock is released

Use mongoimport to import data into mongoDB

The mongoimport tool can load data in three file formats

1. CSV: a file format in which each line represents a document and fields are separated by commas

2. TSV: this file is similar to CSV, using TAB as the delimiter

3. JSON: this file format has a JSON for each line, representing a document. Unlike other formats, JSON can support documents with variable schemas.

Mongoimport-help

MONGODB supports a simple role-based authentication system that controls users' access to the database and the level of access they are granted.

Add admin

Use admin

Db.createUser ({

User: "admin"

Pwd: "root123"

Roles: [{

Role: "readWrite"

Db: "admin"}

{role: "userAdminAnyDatabase", db: "admin"}

]

})

Db.auth ("admin", "root123")

Db.getllsers () / / Information about user permissions

Db.serverStatus ()

Validate and repair data

Repair the server

Using the repair command is an expensive operation that takes a long time and requires twice the size of the MONGODB data file, because all the data is cloned into new files and rebuilt, which is essentially a reconstruction of all data files

Mongod-dbpath / data/db-repair

During large data repair, you can specify a drive with a large space to save temporary files created during the repair.

Mongod-f / etc/mongodb.conf-- repair-- repairpath / tmp/bigdata/

The validata option allows you to verify whether there is a problem with the contents of the collection in the database

Use dblog

Db.posts.ensureIndex ({Author:1})

Db.posts.validate ()

Repair the index of the collection

Db.posts.reIndex () / / online repair of plunger access to the system

Repair the data file of the collection

Use blog

Db.repairDatabase () / / is not suitable for running online because it will group all requests for data when it rebuilds data files, and all read and write requests are blocked during repair.

Optimization of MONGODB

Enable and disable MONGODB Analyzer

Use blog

Db.setProfilingLevel (1) / / 0 shutdown

Db.setProfilingLevel (1500) / / start millisecond level

Db.setProfilingLevel (2) / / all queries start the parser

Find slow query

Db.system.profile.find ()

Increase the size of the parser collection

1. Close the analyzer

Use blog

Db.setProfilingLevel (0)

2. Delete the system.profile collection

Db.system.profile.drop ()

3. Create a new set analyzer

Db.createCollection ("system.profile", {capped:true,size:50*1024*1024})

4. Re-enable the analyzer

Db.setProfilingLevel (2)

Use explain () to analyze specific queries

Use blog

Db.posts.find () explain (true)

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

Internet Technology

Wechat

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

12
Report