Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MongoDB Foundation (3.6installation and multiple instances)

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Introduction to MongoDB

MongoDB is a cross-platform, document-oriented database. It can achieve high performance, high availability, and can be easily scaled. Is an open source database system based on distributed file storage, in the case of high load, adding more nodes can ensure the performance of the server.

MongoDB is also a product between relational database and non-relational database, which is the most functional and most like relational database in non-relational database. The main purpose of not adopting the relational model is to achieve better extensibility. MongoDB no longer has the concept of "row", and its operation mode is mainly based on two concepts: collection and document.

Characteristics of MongoDB

The characteristics of MongoDB include set-oriented storage, free mode, rich query statements and multi-level index, replication set mechanism, easy horizontal expansion, pluggable storage engine, cross-platform and multi-language support and so on.

MongoDB is easy to install, provides document-oriented storage function, and is easy to operate.

MongoDB provides replication, high availability, and automatic sharding. If the load increases (more storage space and more processing power are needed), it can be distributed among other nodes in the computer network, which is called sharding.

MongoDB supports a rich set of query expressions. Query instructions use tags in the form of JSON to easily query objects and arrays embedded in a document.

MongoDB supports a variety of languages: Ruby, Python, Java, C++, PHP, C# and other languages.

Application area of MongoDB

MongoDB can provide scalable high-performance data storage solutions for WEB applications. MongoDB is mainly applicable to website data, distributed scenarios, data caching and JSON document format storage. It is suitable for Internet applications with large amount of data, high concurrency and weak transactions. its built-in horizontal scaling mechanism provides millions to billions of levels of data processing capacity, which can well meet the data storage requirements of Web2.0 and mobile Internet applications.

MongoDB commonly used terms and descriptions SQL terms MongoDB terms explain / explain databasedatabase database tablecollection database tables / collections rowdocument data record rows / documents columnfield data fields / domain indexindex index table joins table join, MongoDB does not support primary keyprimary key primary key, MongoDB automatically sets the _ id field as the primary key

Database: a single MongoDB instance can host multiple databases. They can be regarded as independent of each other, and each database has independent permission control. On disk, different databases are stored in different files. The following system databases exist in MongoDB.

Admin database: a permissions database that automatically inherits permissions from all databases if the user is added to the admin database when the user is created. Local database: this database is never responsible and can be used to store any collection of local individual servers. Config database: when MongoDB uses sharding mode, the config database is used internally to hold sharding information.

Collection: a collection is a set of documents, similar to tables in a relational database. The collection is schemaless, and the documents in the collection can be varied. Collections in MongoDB are represented by collections, each

Collection is identified by a name. You need to pay attention to the following points:

The name cannot be an empty string ""

The name cannot contain\ 0 characters because it represents the end of the name

Cannot be created with system. At the beginning

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

The key / value pairs in the document are ordered.

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

MongoDB is type-and case-sensitive.

MongoDB documents cannot have duplicate keys.

The key of the document is a string. With a few exceptions, keys can use any UTF-8 character. Install MongoDB

1. Configure YUM Source Warehouse

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

two。 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 / / write log 10 path: / var/log/mongodb/mongod.log / / log file path 11 12 # Where and how to store data. 13 storage: 14 dbPath: / var/lib/mongo / / data storage directory 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 background operation 24 pidFilePath: / var/run/mongodb/mongod.pid # location of pidfile 25 timeZoneInfo: / usr/share/zoneinfo 26 27 # network interfaces 28 net: 29 port: 27017 / / default server port number 30 bindIp: 0.0.0.0 / / listening address 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 grep mongodtcp 27017 0.0.0 0 LISTEN 15252/mongod

5. Go to the database and simply view it

Mongo / / enter database > db.version () / / View database version > show dbs / / View all libraries > db.getMongo () / / View the connection address of the current database machine to enable multiple instances

In cases where a single server has sufficient resources, multiple instances can be used to make full use of the server resources. Do the following:

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 / / create the corresponding data storage directory touch / data/mongodb/mongod2.log / / create a log file chmod 777 mongod2.log open mongodb2:#mongod-f / etc/mongod2.conf#mongo-- port 27018MongoDB shell version v3.6.6... > # netstat-ntaptcp 00 0.0.0.0 data/mongodbmkdir 27017 0. 0.0.0 * LISTEN 15252/mongodtcp 0 0 0.0.0.0VERV 27018 0.0.0.0VOUR * LISTEN 3649/mongod

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report