MongoDB Big Data operation and maintenance management

Source: Internet
Author: User
Tags mongodb mongodb server new set mongodump mongorestore

Database Management

Back up the MongoDB server

Execute Mongodump//Use local connection 127 and port to connect local database by default

The database reverts to the state before the backup:

Mongorestore--drop

The ##--drop option tells the Mongorestore tool to discard existing data before recovering the collection, and if this option is not used, the recovered data will be appended to the end of each collection, causing duplication of data

Backing up a single database

Mongodump-d Database_name-c Post # #备份指定库下集合

--help

Recovering a single database

Mongorestore-d Blog--drop

Recovering a single collection

Mongorestore-d blog-c Posts--drop


Backing up large databases

Database backup system has a must kill skill, is a point-in-time snapshot, it is very fast, the faster the snapshot completion, the database server needs to be frozen less time

Creating a hidden secondary server in MongoDB is very simple, and you can use MongoDB's replication mechanism to ensure that he and the primary server have been

1 Creating a snapshot using the log file system

2 Backing up data using a hidden secondary server



MongoDB executes FYSNC and lock to ensure that the database on disk is mirrored in a consistent state and that they remain consistent until the snapshot is completed

Use admin

Db.fsynclock ()//Enter Fsync and lock state

View the status of the current lock

Use admin

Db.currentop ()

Release lock

Db.fsyncunlock ()//Lock release may have a short delay before

Data import MongoDB using Mongoimport

The Mongoimport tool can load data in 3 different file formats

1. CSV: This file format, each line represents a document, the fields are separated by commas

2. TSV: This file is similar to CSV, it uses tab as the delimiter

3, JSON: The file format each line of a JSON, representing a document, unlike other formats, JSON can support mutable schema of the document

Mongoimport--help

MongoDB supports a simple role-based authentication system that controls user 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 ()//user Rights related information

Db.serverstatus ()


Validating and repairing data

Repair Server

Using the repair command is a costly operation that consumes a lot of time and requires two times the size of the MongoDB data file because all the data is cloned from the new file and rebuilt, essentially rebuilding all the data files

Mongod--dbpath/data/db--repair

During a large data repair process, you can specify a large space for the drive to hold temporary files created during the repair process

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


The Validata option enables you to verify the contents of a collection in a database for problems

Use DBLog

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

Db.posts.validate ()


Repairing the index of a collection

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

Repairing a collection of data files

Use blog

Db.repairdatabase ()//is not suitable for online operation because it rebuilds data files when all requests for data are set, and all read and write requests in the repair process are blocked


MongoDB optimization

enabling and disabling the MONGODB parser

Use blog

Db.setprofilinglevel (1)//0 off

Db.setprofilinglevel (1,500)//start millisecond level

Db.setprofilinglevel (2)//All Queries start analyzer

Find slow Queries

Db.system.profile.find ()


Increase the size of the parser collection

1. Close Analyzer

Use blog

Db.setprofilinglevel (0)

2. Delete System.profile Collection

Db.system.profile.drop ()

3. Create a new set parser

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

4. Re-enable analyzer

Db.setprofilinglevel (2)

Use explain () to analyze specific queries

Use blog

Db.posts.find (). Explain (true)


MongoDB Big Data operation and maintenance management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.