MongoDB Foundation (Installation and multi-instance)

Source: Internet
Author: User
Tags install mongodb mongodb

About MongoDB

MongoDB is a cross-platform, document-oriented database. Can achieve high performance, high availability, and can easily scale. is a distributed file storage based open source database system, in the case of high load, add more nodes, can guarantee the performance of the server.
MongoDB is also a product between a relational database and a non-relational database, the most versatile of the non-relational databases, most like relational databases. Instead of using relational models primarily for better extensibility, MongoDB no longer has the concept of "row", which works primarily on two concepts: Collections (collection) and documents.

Features of MongoDB

MongoDB features include collection-oriented storage, schema freedom, rich query statements and multilevel indexes, replication set mechanisms, easy horizontal scaling, pluggable storage engines, cross-platform multi-language support, and more.
MongoDB is simple to install and provides a document-oriented storage function that is easier to operate.
MONGODB provides replication, high availability, and automatic sharding capabilities. If the load increases (requiring more storage space and greater processing power), it can be distributed across other nodes in the computer network, which is called sharding.
MongoDB supports rich query expressions. Query directives use a JSON-style tag to easily query objects and arrays embedded in the document.
MongoDB supports a variety of languages: Ruby, Python, Java, C + +, PHP, C #, and more.

MongoDB Areas of Application

MongoDB can provide scalable, high-performance data storage solutions for Web applications. MongoDB's main areas of application are Web site data, distributed scenarios, data caches, and JSON document format storage. Suitable for Internet applications with large data volumes, high concurrency, and weak transactions, the built-in horizontal scaling mechanism provides millions of to 1 billion levels of data processing capability, which can meet the requirements of Web2.0 and mobile Internet application storage.

MongoDB Common Terms and descriptions
SQL Terminology MongoDB Terminology Explanation/Description
Database Database Database
Table Collection Database Tables/Collections
Row Document Data record lines/documents
Column Field Data fields/Fields
Index Index Index
Table joins Table connection, MongoDB not supported
Primary key Primary key Primary key, MongoDB automatically sets the _id field as the primary key

database : A MongoDB instance can host multiple databases. They can be considered independent of each other, and each database has independent permissions control. On disk, different databases are stored in different files. The following system databases exist in MongoDB.

    • Admin database: A rights database, if the user is created when the user is added to the admin database, then the user automatically inherits all the permissions of the database.
    • Local database: This database is never responsible and can be used to store any collection of local single servers.
    • Config database: When MongoDB uses shard mode, the Config database is used internally to hold information about the Shard.

Collection : A collection is a set of documents, similar to a table in a relational database. Collections are modeless, and the documents in the collection can be of various kinds. The collection in MongoDB is represented by collections, each
Collection with a name, the following points need to be noted:

    • The name is not allowed to be an empty string ""

    • The name cannot contain the \ s character because it represents the end of the name

    • You cannot create a system that begins with the.

Document: A document is the basic unit of data in MongoDB, similar to a row in a relational database (but more complex than a row). Multiple keys and their associated values are placed together in order to form the document.

    • The key/value pairs in the document are ordered.

    • The values in the document can be not only strings in double quotes, but also several other data types (even the entire embedded document).

    • MongoDB distinguishes between type and case.

    • MongoDB documents cannot have duplicate keys.

    • The key of the document is a string. In addition to a few exceptions, keys can use any UTF-8 character.
Installing MongoDB

1. Configure the Yum source repository

cd /etc/yum.repos.d/vim mongodb-org.repo[mongodb-org]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

2. Install MongoDB Online

yum install -y mongodb-org

3. Modify the configuration file

vim /etc/mongod.service  1 # mongod.conf  2   3 # for documentation of all options, see:  4 #   http://docs.mongodb.org/manual/reference/configuration-options/  5   6 # where to write logging data.  7 systemLog:  8   destination: file  9   logAppend: true       //使用追加方式写日志 10   path: /var/log/mongodb/mongod.log     //日志文件路径 11  12 # Where and how to store data. 13 storage: 14   dbPath: /var/lib/mongo        //数据存储目录 15   journal: 16     enabled: true 17 #  engine: 18 #  mmapv1: 19 #  wiredTiger: 20  21 # how the process runs 22 processManagement: 23   fork: true  # fork and run in background后台运行 24   pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile 25   timeZoneInfo: /usr/share/zoneinfo 26  27 # network interfaces 28 net: 29   port: 27017           //默认服务器端口号 30   bindIp: 0.0.0.0  //监听地址 31  32  33 #security: 34  35 #operationProfiling: 36  37 #replication: 38

4. Turn off the firewall and enhance security features and open the database

systemctl stop firewalld.servicesetenforce 0systemctl start mongod.servicenetstat -anpt | grep mongodtcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      15252/mongod

5. Enter the database and make a simple view

mongo                 //进入数据库>db.version()          //查看数据库版本>show dbs              //查看所有库>db.getMongo()         //查看当前数据库机器的连接地址
Turn on multi-instance

With sufficient resources for a single server, multiple instances can be used to make full use of server resources. The operation is as follows:

cp -p /etc/mongod.conf /etc/mongod2.confvim /etc/mongod2.conf   ...   path: /data/mongodb/mongod2.log   dbPath: /data/mongodb/mongo   ...     port: 27018   ...mkdir -p /data/mongodbmkdir /data/mongodb/mongo       //创建对应的数据存储目录touch /data/mongodb/mongod2.log     //创建日志文件    chmod 777 mongod2.log
开启mongodb2:#mongod -f /etc/mongod2.conf#mongo --port 27018MongoDB shell version v3.6.6 ...>#netstat -ntaptcp        0      0 0.0.0.0:27017           0.0.0.0:*               LISTEN      15252/mongodtcp        0      0 0.0.0.0:27018           0.0.0.0:*               LISTEN      3649/mongod

MongoDB Foundation (Installation and multi-instance)

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.