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

How to deploy MongoDB database application

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

Share

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

This article mainly introduces the relevant knowledge of how to deploy MongoDB database applications, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to deploy MongoDB database applications. Let's take a look.

A brief introduction to MongoDB

MongoDB, written in C++ language, is a non-relational open source database system based on distributed file storage. Its advantage is that it can store a large amount of data, has a powerful query function, and is an independent collection-oriented document form.

Application platform: MongoDB supports Unix Linux Windows and other system platforms.

The difference between MySQL and MongoDB:

MySQL database data table data MongDB database collection document 1.MongoDB characteristics

Storage:

Set oriented: data is grouped and stored in a dataset, which is called a collection.

Document oriented: documents stored in collections are stored in the form of key-value pairs.

Efficient binary data storage: using binary format storage, you can save any type of data object.

Maneuverability:

Full index: you can index on any property, including internal objects. To improve the speed of the query.

Powerful aggregation tools: MongoDB not only provides rich query functions, but also provides powerful aggregation tools, such as count group.

Drivers that support Perl PHP Java C # JavaScript Ruby Python C and C++ language.

Availability:

Support replication and data recovery: MongoDB supports master-slave replication mechanism, which can achieve data backup, fault recovery, read expansion and other functions. The replication mechanism based on replica set provides the function of automatic fault recovery, which ensures that the cluster data will not be lost.

Automatic processing of sharding: MongoDB supports cluster automatic data sharding. Data sharding can be used to store more data in the cluster, achieve a larger load, and ensure the load balance of storage.

2.MongoDB applicable scenario

Website real-time data processing: it is very suitable for real-time insertion, update and query, and has the replication and high scalability required for website real-time data storage.

Caching: it is suitable as the cache layer of the information infrastructure. After the system restarts, the persistence cache layer built by it can avoid the data source overload of the lower layer.

Highly scalable scenario: ideal for databases made up of dozens or hundreds of servers.

Scenarios that do not apply are as follows:

Traditional businesses that require highly transactional systems (e.g. banking and accounting systems) can only be applied. Complex cascading queries across documents (tables).

3.MongoDB storage structure

Logical structure:

Document document: the data stored.

Collection collection: consists of multiple documents, equivalent to tables, but the difference is that the collection has no fixed schema.

Database database: a database consisting of multiple collections.

Physical structure:

.wt file: each table or index corresponds to a namespace, the amount of data increases, the number of files increases, and the disk space allocated and in use is stored.

Data file: an entity that stores data and uses a pre-allocated space mechanism.

Log files: system log files, journal log files (guarantee for MongoDB crash recovery), oplog replication operation log files (equivalent to MySQL's BinLog files), slow query logs (statements where the query operation exceeds the specified time)

The physical structure is the real location where the data is stored.

4.MongoDB data type

Second, deploy MongoDB database application hostname operating system IP address version MongoDBCentOS 7.4192.168.1.1mongodb-linux-x86_64-rhel70-4.4.5.tgz1. Prepare the system environment [root@MongoDB ~] # ulimit-n 25000 # maximum number of files opened at the same time [root@MongoDB ~] # ulimit-u 25000 # programs most opened by users The number [root@MongoDB ~] # echo 0 > / proc/sys/vm/zone_reclaim_mode # sets kernel parameters. When one node runs out of memory, you can borrow the memory of other nodes [root@MongoDB ~] # sysctl-w vm.zone_reclaim_mode=0vm.zone_reclaim_mode = 0 [root@MongoDB ~] # echo never > / sys/kernel/mm/transparent_hugepage/ enabled [root @ MongoDB ~] # echo never > / sys/kernel/mm/transparent_hugepage/defrag

Because the following installation version is 4.4.5, and the tools in the / bin directory above MongoDB 4 are detached, you need to install: portal

[root@MongoDB] # tar xf mongodb-database-tools-rhel70-x86_64-100.3.1.tgz2. Install MongoDB [root@MongoDB ~] # wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.5.tgz[root@MongoDB ~] # tar xf mongodb-linux-x86_64-rhel70-4.4.5.tgz [root@MongoDB ~] # mv mongodb-linux-x86_64-rhel70-4.4.5 / usr/local/mongodb [root@MongoDB ~] # mv mongodb-database-tools-rhel70-x86_64-100.3.1 / bin/* / usr/local/mongodb/bin/ [root@MongoDB ~] # echo "export PATH=/usr/local/mongodb/bin:\ $PATH" > > / etc/profile [root@MongoDB ~] # source / etc/profile3. Create MongoDB storage directory and configuration file [root@MongoDB ~] # mkdir / usr/local/mongodb/ {data,logs Conf} [root@MongoDB ~] # touch / usr/local/mongodb/logs/mongodb.log [root@MongoDB ~] # chmod 777 / usr/local/mongodb/logs/mongodb.log [root@MongoDB ~] # cat show databases # View all libraries in the database admin 0.000GBconfig 0.000GBlocal 0.000GB > db.getName () # View the current login library test

The default 4 libraries after MongoDB installation:

Admin: stores information about database accounts.

Config: used in sharding cluster environment to store shard-related metadata information.

Local: used to store any collection limited to a single local server (because the library is not copied to the slave node, in short, there is no redundancy)

A test library created by test:MongoDB by default. When connecting to a MongoDB service, if you do not specify a specific database to connect to, it will connect to the test library by default.

This is the end of the article on "how to deploy MongoDB database applications". Thank you for reading! I believe you all have a certain understanding of "how to deploy MongoDB database applications". If you want to learn more, you are welcome to follow the industry information channel.

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

Development

Wechat

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

12
Report