MongoDB (iv)--management architecture

Source: Internet
Author: User
Tags auth mongodb server

The front introduces the basis of MongoDB, here are recommended two sites, you can view, explain or more detailed: 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. OK, first look at the picture:

Below, follow this diagram to introduce each one.

One, management, of course, mainly on the management of the database, including our most concerned about the data, and the management of the data users. This is important for both non-relational and relational databases.

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 window, under the path of the D:\mongodb\bin, using the Mongoexport command, can be mongoexport-help to help query. 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 usage, you can import JSON format data, or you can export the CVS data format. Mongoimport-h: Indicates the database host's ip-u: Indicates the database's user name-P: Indicates the database's password-D: Indicates the name of the database-C: Indicates the name of the collection--type CVS--headerline (named First row is the column name, No import required)--file files to import

Import and export is very simple, skilled use of these two commands.

2, data Backup and recovery: Data priceless, with the advent of today's big data era, data is increasingly important, the preservation of good data, is equivalent to the preservation of value, so the database backup and recovery work is also very important, here to see the backup and operation of MongoDB.

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

Parameter description:

-H: Indicates the IP of the database host

-U: Indicates the user name of the database

-P: Indicates the password for the database

-D: Indicates the name of the database

-C: Indicates the name of the collection

-O: Indicates the file name to be exported

-Q: Indicates the filtering criteria for the exported data

Recovery: Command Mongorestore under Bin

Parameter description:

-H: Indicates the IP of the database host

-U: Indicates the user name of the database

-P: Indicates the password for the database

-D: Indicates the name of the database

-C: Indicates the name of the collection

-O: Indicates the file name 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 a super administrator, a database administrator for each database. By default, there is no permission authentication, only the database authentication user can read and write after the security authentication is enabled. When you specify--auth on startup, permission authentication is added.

1. Add and verify the user, where this is to add a user to this data test, and the third parameter is Readonly,true or FALSE, indicating 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 added to the admin is a super administrator and can manage other databases, but the login verification of each database must be verified from the database that it manages, and the super management must be managed by admin and then switched 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, that is, Master (master server), but it can divide the read operation to other slave (from the server). This is the master-slave, this situation, when the primary server is down, we need to manually change one from the server to the primary server, which is also a bad place.

First of all, we need to install two MongoDB servers (of course, we can also use a server on different ports).      Then the master server starts the command: Mongod--master--DBPA "The path to the database"--logpath "the path to the log"--port port number so that our master server is finished. Start from server command: Mongod--slave--source Primary server IP: The port number of the primary server's MongoDB--DBPA "the path to the database"--logpath "the path to the log"--port port number such that our master server Starting from the server is OK, of course we can create multiple slave servers. Then we can be in the main server for the pruning operation, see the data from the server will change with the master server changes, so as to achieve, MongoDB's master-slave distribution.

2,replica set (replica set) replication, this distributed cluster, mainly increases the failure of automatic switching and automatic repair of member nodes, the data between each db exactly the same. And the most notable difference between the master and slave is that it has no fixed node, it is the entire cluster election of a master node, when it is not working properly, other nodes are strongly recommended to use.

Deployment steps: A, create a data storage path and log storage path for each MONGODB server, respectively

b, create a master-slave key file to identify the private key of the cluster, in which the same private key is stored and changed to read-only form.

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

D, configure initialize replica sets, that is, configure this collection: Log on any one: config_rs1={_id: "Rs1", Members:[{_id:0,host: "Server 1IP: Port", Priority:1 (priority)} , {id:1,host: "Server 2IP: Port", Priority:2 (Priority)}]}

Then initialize the configuration: Rs.initiate (CONFIG_RS1); OK then

This will be done, the higher the priority number, the higher the priority, the higher this one will be automatically selected as the main server, you can make additional deletion check, while the other is from the server can be read, note: Rs.slaveok ();

Well, let's take an example to understand both of these architectures. Master-slave replication is like the primary class, copy-set replication is like college classes. Each class has a monitor, is the master server, the other students are slave server. Through the monitor can be on the class matters to increase and revise, and through the students can only to the class matters to understand the query. The monitor of the primary school takes leave, needs 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, does not need the teacher's intervention.

OK, this article on the first to this, MongoDB learning has yet to be greatly deepened, through the use of continuous understanding, constantly familiar, and constantly sublimation.

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.