Install and start MongoDB 3.0 in RHEL7

Source: Internet
Author: User
Tags install mongodb

Install and start MongoDB 3.0 in RHEL7

MongoDB Introduction

MongoDB is an open-source document-type database that supports indexing, replication (replica set), and data sharding. It can be used to build a high-performance, highly available, and Scalable Server Cluster.

Different from MySQL:
1. Non-relational, self-contained data. Although similar documents are stored in a collection, there is no relationship between documents, and the collection is similar.
2. There is no table or row concept. It corresponds to a set and a document, and there is no foreign key or connection. However, in version 3.2, a left Outer Join is provided to another set.
3. No mode. The document structure in the set is not fixed and various documents can be stored.
4. transactions are not supported, but they do not mean they cannot be used to manage important data (MySQL's MYISAM storage engine does not support transactions ...)

A record in the database is a document, which can be embedded in a document. The structure is similar to JSON. It is officially called BSON. Multiple documents form a set and multiple sets form a database.

This article mainly records some concepts and terminologies of MongoDB. Operations on MongoDB and cluster construction will be sorted out later.

Database: stores documents and collections. Like MySQL, you can use <db> to select a database. If the selected database does not exist, you can directly create a database when you first operate the database.
For example:
Use myDb
Db. book. insert ({"x": 1 })
A myDb database and a book collection will be created.
Collection: stores documents, which is equivalent to RDBMS tables. We can add, delete, update, query documents, create and delete indexes for collections, when data is inserted for the first time, a set is created implicitly,
You can also use db. createCollection () to explicitly create a collection. In analyticdb 3.2, you can specify to insert a collection to verify the document.
In addition, there is a special set, which is fixed and its size is fixed,
For example, db. createCollection ("log", {capped: true, size: 10000}) can only store 10000 bytes of data.
Db. createCollection ("log", {capped: true, size: 10000, max: 5000}) can only store 10000 bytes of data, and the number of documents cannot exceed 5000
Document: the place where data is stored. The document structure is similar to that of JSON.

First, let's take a look at the data types supported by MongoDB:
1. String: String UTF-8;
2. Integer: 32-bit int or 64-bit long;
3. Double: floating point number;
4. Boolean: true or false;
5. Null: Null or nonexistent field;
6. Array: [1, 2, 3]
7. objectId: Each document has a unique identifier "_ id", which is of the ObjectId type. during insertion, we generally do not need to specify it. The database will automatically generate it, of course, we can also specify the value of this field when inserting a document, but it must be unique. Otherwise, an error will be reported during insertion. "_ id" is the default index of the database;
8. date: A 64-bit integer that stores the number of milliseconds from 1970.1.1 to the present, var date = new Date (); If you store the data directly, it seems that the database is 8 hours slow, (+ 8 time zone)
9. Timestamp: Timestamp, 64-bit value, var a = new Timestamp ();
10. Regular Expression: Regular Expression, which is a condition for query. The syntax is the same as that of JavaScript.
11. Binary: Binary data
11. Min key,
12. Max key.

When different types are sorted, the values of each type are as follows:
1. MinKey (internal type)
2. Null
3. Numbers (ints, longs, doubles)
4. Symbol, String
5. Object
6. Array
7. BinData
8. ObjectId
9. Boolean
10. Date
11. Timestamp
12. Regular Expression
13. MaxKey (internal type)

The above are some common types
Limitations of the document: Each document cannot exceed 16 Mb. For large files such as movies and images, MongoDB uses GridFS for block storage.

> Db. foo. insert ({
... "String": "UTF-8 string ",
... "Integer": NumberLong (1461334508012 ),
... "Double": 3.14159265,
...... "Boolean": true,
... "Null": "null ",
... "Array": [1, 2, 3, "a"],
... "Date": new Date (),
... "Timestamp": new Timestamp ()
......})
WriteResult ({"nInserted": 1 })
> Db. foo. find ()
{"_ Id": ObjectId ("571a33d6ef35d50971b1c675"), "String": "UTF-8 string ",
"Integer": NumberLong ("1461334508012"), "Double": 3.14159265,
"Boolean": true, "Null": "null", "Array": [1, 2, 3, "a"],
"Date": ISODate ("2016-04-22T14: 23: 18.762Z"), "Timestamp": Timestamp (1461334998, 1)
}

Indexes, like relational databases, are used to increase the query speed. When sharding is performed, the premise of the partition key is the index. As the index increases, the total data capacity increases, the database write speed gradually slows down. Previously, we tested MongoDB specifically. The test server is GB memory, 34CPU... the test report will also be prepared and posted, and you can find a chance to test and compare MySQL.

With regard to aggregation, the main operation of the project is to insert and query, and will not be written at the moment. It will be used in the future

Storage engine: Before 3.0, the default storage engine is MMAPV1. In 3.0, WiredTiger storage engine is supported. In 3.2, WT engine is set to default. There are some differences between the two, the lock granularity is different. MMAPV1 is a set-Level Lock, and WT is a document-Level Lock. in highly concurrent writes, WT has high performance. The WT engine should be fully compatible with the MMAPV1 engine and support document compression, for more details, see the release description of MongoDB.

Replication: data synchronization across multiple servers improves data redundancy and availability.
Replica set replSet is actually a group of mongod processes with the same dataset. It contains three types of members: master node, secondary node, and arbitration node (data is not stored, but used for voting ).
All write operations on the client are performed on the master node, and related operations are recorded in the oplog operation log. The slave node replicates oplog asynchronously, then, apply the corresponding operations to your own dataset. When the master node is unavailable or does not communicate with other nodes for more than 10 seconds, automatic failover will take place. The replica set automatically selects a node as the master node, and the arbitration server ensures that the election is normal.
Replica set minimum requirements: one master node, one slave node, and one arbitration Node
A standard configuration is a master node with two secondary nodes and three members in total.
If you have an even number of replica integration members, add an arbitration node to become an odd number.

For more information about replica sets, see the official documentation https://docs.mongodb.org/manual/core/replication-introduction/.

Sharding: splits data to the shard server according to the specified rule (partition Key), which reduces the read/write pressure on the server and facilitates expansion.

Authentication: by default, access control is disabled for MongoDB. You can use -- auth or set security. authorization to enable authentication,
MongoDB users have the following permissions:
"Read": read Permission
"ReadWrite": read/write permission
"DbAdmin": Execute management Command Permissions, such as creating or deleting indexes, to view statistics
"DbOwner": equivalent to the combination of readWrite, dbAdmin and userAdmin
"UserAdmin": Create, delete, and manage user permissions.

Admin database permissions, only available in admin Database
"ClusterAdmin": Command permission for sharding and replica set, maximum cluster operation permission
"ReadAnyDatabase": Read Permission for all databases
"ReadWriteAnyDatabase": read and write permissions for all databases
"DbAdminAnyDatabase": dbAdmin permissions for all databases
"UserAdminAnyDatabase": userAdmin permissions for all databases

Super User permission
"Root": all resources are accessible and all operations are performed.
You can also customize user roles.

The writing is a bit messy. Next, simulate a MongoDB cluster in the Virtual Machine and write a client for testing in Java. When creating and testing a cluster, you can choose to enable access control or not enable access control.

For more details, please continue to read the highlights on the next page:

For more MongoDB tutorials, see the following:

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

MongoDB beginners must read (both concepts and practices)

MongoDB Installation Guide for Ubunu 14.04

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

Nagios monitoring MongoDB sharded cluster service practice

Build MongoDB Service Based on CentOS 6.5 Operating System

  • 1
  • 2
  • Next Page

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.