MongoDB (iv)--management architecture

Source: Internet
Author: User
Tags auth

the previous introduction to the MongoDB Foundation, here we recommend two sites, we can look at, the comments are quite specific: http://www.w3cschool.cc/mongodb/mongodb-tutorial.html. http://www.yiibai.com/mongodb/mongodb_create_backup.html#. Ok this article look at MongoDB Data management, architecture building. Good. take a look at the picture first:

The following is a description of the picture below.

One, management, of course, is mainly the management of the database, including our most concerned about the data. And the users who manage this data.

Regardless of the non-relational or relational database. This is all very important.

1, Import and Export data: for MONGODB data import and export, the use of the bin command Mongoexport (export), Mongoimport (import).

Mongoexport: The default exported JSON-formatted file.

Enter the DOS command form and, under the D:\mongodb\bin path, use the Mongoexport command to help query through Mongoexport-help. Syntax: mongoexport-d mydatabase-c mycollection--port port--cvs-f columns to export-0 Specify the path name of the Export + file name

Mongoimport: As with the above method, it is possible to import JSON format data as well as to export the CVS data format.

Mongoimport-h: Indicates the ip-u of the database host: Indicates the username-p of the database: Indicates the password-d of the database: Indicates the name of the database-C: Indicates the collection name--type CVS--headerline ( Name the first row is the column names, no need to import)--file files to import

Import and export very easy, skilled use of these two commands can be.

2, data Backup and recovery: The data is priceless. With the advent of today's big data era, data is becoming more and more important, keeping the data good. is equivalent to preserving the value, so database backup and recovery work is also very important, here to look at MongoDB backup and operation.

Backup: Also the command mongodump under the bin, relatively simple:

Description of the parameters:

-H: Indicates the IP of the database host

-U: Indicates the username of the database

-P: Indicates the password of the database

-D: Indicates the name of the database

-C: Indicates the name of the collection

-O: Indicates the name of the file to export

-Q: Indicates the filtering criteria for the exported data

Recovery: Command Mongorestore under Bin

Description of the parameters:

-H: Indicates the IP of the database host

-U: Indicates the username of the database

-P: Indicates the password of the database

-D: Indicates the name of the database

-C: Indicates the name of the collection

-O: Indicates the name of the file to be backed up

-Q: Indicates the filter condition of the backup data

3, user management, MongoDB inside user management, he has two types of users. One is the Super administrator, a database administrator for each database. By default, authentication is not granted. Only after security authentication has been enabled. Database authentication is sufficient for the user to read and write.

When you specify--auth on startup, you are granted permission authentication.

1. Join and verify the user, which is to add the user to this data test, the third parameter is Readonly,true or FALSE, indicates whether it is read-only.

> Use test

> Db.adduser ("Zjx", "Tsjianxin")

> Db.auth ("Zjx", "Tsjianxin")

2. View existing users

> Db.system.users.find ()

3. Delete a user

> Use dbname (admin or 51CV, etc)

> Db.system.users.remove ({User: "haha"})

> Db.system.users.find ()

The user who added to the admin is a super administrator, able to manage other databases, but each database login verification must be verified from the database of its own management, super management must be managed through admin. Then switch to manage the other databases.

Second, the structure of the article, here is a simple look at the construction of a distributed database, mainly from the replication and replica sets of two cases, a simple look.

1,master-slave (Master-slave) replication: MongoDB supports failover and implementation redundancy across multiple machines through asynchronous replication. At the same time in a multi-machine, only one is used for write operations. This is master (master server), but it is able to divide the read operation to other slave (from server). This is the master-slave, this situation, when the main server is down, it is necessary for us to manually change one from the server to the primary server, this is also a bad form of the place.

First of all, we need to install two mongodbserver (and of course, a server.) On a different port). Then the main server starts the command: Mongod--master--DBPA "The path to the database"--logpath "the path to the log"--port port number so that our host server is finished.

From the server startup command: Mongod--slave--source Primary server IP: The port number of the primary server MongoDB--DBPA "The path to the database"--logpath "the path to the log"--port port number This Kind of our home server from the server also started well, of course we can create multiple from the server. Then we were able to make a pruning operation on the primary server to see that the data from the server would change with the change of the primary server, thus achieving the master-slave distribution of MongoDB.

2,replica set (replica set) replication, such a distribution cluster, mainly adds the problem itself to proactively switch and self-repair member nodes. The data between the various DB is exactly the same. The most significant difference between the master and the subordinate is that there is no fixed node, it is a primary node that is elected by the whole cluster, and when it is not working properly, other nodes are highly recommended.

Deployment steps: A to create a data storage path and log storage path for each mongodbserver

b, create a master-slave key file to identify the private key of the cluster. The same private key is stored inside. Instead of just reading the form.

C, each server starts: Mongod--replset rs1 (replica set name, same can)--keyfile Key's path--port port number--dbpath database storage path--logpath log path

d, configuration initialization replica sets, that is, to configure this collection: Login arbitrarily: config_rs1={_id: "Rs1", Members:[{_id:0,host: "Server1ip: Port", Priority:1 ( Priority)}. {id:1,host: "Server2ip: Port", Priority:2 (Priority)}]}

Then initialize the configuration: Rs.initiate (CONFIG_RS1); OK, you can.

This will be done, the greater the priority number. The higher the priority level. The high of this one will take its own initiative to choose the main server. Be able to carry on the additional deletion check. The other is from the server to be able to read. Note: Rs.slaveok ();

Good. The last example. To understand both of these architectures.

Master-slave replication is like the primary class, copy-set replication is like college classes.

Every class has a monitor. Is Masterserver. The other students are slaveserver. Through the monitor can be on the class matters to increase and revise, and through the students only to the class matters to understand the query. The monitor of the primary school took leave, need our teacher to appoint a monitor, the student does not have the consciousness to recommend, but the university class, then will be recommended by the student, need not the teacher's intervention.

Big, this will be the first, MongoDB in-depth study still needs to be greatly, through the use of continuous deep understanding. Constantly familiar,. Continuous distillation.

MongoDB (iv)--management architecture

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.