MongoDB (IV)-management architecture and mongodb Management Architecture

Source: Internet
Author: User
Tags mongodb port number mongodb server

MongoDB (IV)-management architecture and mongodb Management Architecture

We have introduced the basics of MongoDB. We recommend two websites here. You can check them and explain them in detail #. Let's take a look at MongoDB's data management and architecture. Well, let's take a look at the figure:

 

 

See the following figure for details.

I. Management, of course, mainly refers to database management, including the data we are most concerned about and the users who manage the data. Whether it is a non-relational database or a relational database, this is very important.

 

1. Data Import and Export: for MongoDB data import and export, the bin command export Export (export) and Export Import (import) are used ).

 

Export export: Default exported file in JSON format. Enter the doscommand window. In the path d: \ mongodb \ bin, you can use the export Export command to query the help information through export-help. Syntax: Export export-d mydatabase-c mycollection -- port -- cvs-f column to be exported-0 specify the exported path name + file name

 

Export Import: similar to the preceding method, you can import JSON data or export cvs data format. Export Import-h: Specify the IP address of the Database Host-u: Specify the database username-p: Specify the Database Password-d: Specify the database name-c: specify the name of the collection -- type cvs -- headerline (the first row is the column name, no need to import) -- file to import the file

 

The import and export operations are simple. You can use these two commands.

 

2. data backup and recovery: data is priceless. With the advent of the big data era, data is becoming more and more important. Saving data is equivalent to saving value, therefore, database backup and recovery are also very important. Here we will take a look at Mongodb backup and operations.

 

Backup: it is also the bin command mongodump, which is relatively simple:

Parameter description:

-H: Specifies the IP address of the Database Host.

-U: Specifies the database user name.

-P: Specifies the Database Password.

-D: Specifies the database name.

-C: Specifies the collection name.

-O: Specifies the file name to be exported.

-Q: specify the criteria for filtering the exported data.

 

Restore: The command mongorestore in bin

Parameter description:

-H: Specifies the IP address of the Database Host.

-U: Specifies the database user name.

-P: Specifies the Database Password.

-D: Specifies the database name.

-C: Specifies the collection name.

-O: Specifies the file name to be backed up.

-Q: Specify the filtering conditions for backup data.

 

3. User Management: User Management in mongodb. There are two types of users: Super administrator and database administrator for each database. By default, there is no permission authentication. Database authenticated users can perform read/write operations only after security authentication is enabled. If -- auth is specified at startup, permission authentication is added.

1. Add and verify the user. This is to add the user to the test data. The third parameter is readOnly, true or false, indicating whether the user 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. However, the login verification of each database must be performed from the database managed by the Administrator, and the super management must be managed through the admin, switch to manage other databases.

 

 

Ii. architecture. Let's take a brief look at the construction of a distributed database, which involves master-slave replication and replica set.

 

1. Master-Slave (Master-Slave) replication: MongoDB supports failover and redundancy among multiple machines through asynchronous replication. Only one of multiple machines is used for write operations at the same time, that is, the Master (Master server), but it can distribute read operations to other slave (slave server ). This is the Master/Slave Mode. In this case, when the master server goes down, we need to manually change a slave server to the master server. This is also a bad form.

 

First, we need to install two MongoDB servers (of course, one server can be used on different ports ). Then the command started by the master server is mongod -- master -- dbpa "database path" -- logpath "Log Path" -- port number, so that our master server is complete. Start the slave server command: mongod -- slave -- source master server ip Address: the mongodb port Number of the master server -- dbpa "database storage path" -- logpath "log storage path" -- port number is the slave server of the master server, of course, we can create multiple slave servers. Then, we can add, delete, modify, and delete data on the master server. It can be seen that the data on the slave server changes with the change of the master server. In this way, the master-slave distribution of mongodb is achieved.

 

2. Replica Set (Replica Set) replication. In this distributed cluster, automatic failover and Automatic Repair of member nodes are mainly added. The data in each database is the same. The most significant difference between a master node and a slave node is that it does not have a fixed node. It is a master node elected by the entire cluster. When the total work is not normal, it is strongly recommended to use other nodes.

 

Deployment steps: a. Create a data storage path and a log storage path for each mongoDB server.

B. Create Master/Slave key Files respectively to identify the private key of the cluster. The same private key is stored in the file and changed to read-only.

C. Start each server: mongod -- replSet rs1 (replica set name, same) -- keyFile key Path -- port number -- dbpath database storage path -- logpath Log Path

 

D. Configure the initialization Replica Sets, that is, to configure this set: log on to any of the following Sets: 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.

 

In this way, the higher the priority, the higher the priority. The higher priority will be automatically selected as the master server, which can be added, deleted, modified, and queried. The other one is read from the server. Note: rs. slaveOk ();

 

Okay. Let's take an example to understand the two architectures. Master-slave replication is like a primary school class, and replica set replication is like a university class. Each class has a shift leader, namely the master server, and other students are slave servers. The shift leader can add, delete, modify, and Query Class matters, while students can only Query Class matters. The class leader of the primary school asks for leave. Our teacher needs to designate another class leader. students do not have the consciousness to recommend the class, but the university class will be recommended by the students themselves without the intervention of the teacher.

 

Well, this is the first thing we can do here. mongoDB's learning needs to be further explored. Through continuous understanding, familiarity, and sublimation, we will continue to use mongoDB.

 

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.