Detailed steps for deploying mongodb in Linux

Source: Internet
Author: User
Tags install openssl

Detailed steps for deploying mongodb in Linux
Application scenarios

MongoDB is a distributed file storage-based database. Written in C ++. It is designed to provide scalable, high-performance data storage solutions for WEB applications. MongoDB is a product between relational databases and non-relational databases. It has the most abundant functions and features like relational databases. The supported data structure is very loose and is similar to the json bson format, so it can store more complex data types. The biggest feature of Mongo is that it supports a very powerful query language. Its syntax is somewhat similar to an Object-Oriented Query Language. It can almost implement most of the functions similar to single-table queries in relational databases, it also supports data indexing.

Step 1. MongoDB Introduction

For a large website, traditional relational databases are insufficient to meet the needs of high-concurrency database reading and writing, efficient access to massive data, high scalability and high availability, in addition, the cost required to increase the scale is prohibitive, while flexible, scalable, highly available, and high-performance NoSQL databases have obvious advantages in processing big data.

MongoDB is an open-source, high-performance, and scalable document database. It is a NoSQL database product between relational databases and non-relational databases, its main goal is to build a bridge between key/value storage (providing high performance and high scalability) and traditional relational databases (rich functions), combining the advantages of both. MongoDB supports a loose data structure, which is similar to the json bson format. Therefore, it can store complex data types. Its syntax is a bit similar to the Object-Oriented Query Language. It can almost implement a vast majority of functions similar to the single-Table query of relational databases, and supports data indexing.

1.1 applicable scenarios

Website data: Suitable for real-time insertion, update, and query, as well as the replication and high scalability required for real-time website data storage;

Cache: Suitable for serving as the cache layer of infrastructure. After the system is restarted, the cache layer can avoid data source overload in the lower layer;

Large-sized and low-value data: relational databases may be expensive to store the data, and many choose to store the data as files;

High scalability: Suitable for databases composed of dozens or hundreds of servers;

For object and JSON Data Storage: MongoDB's BSON data format is very suitable for file-based format access.

1.2 inapplicable scenarios

Highly transactional systems: traditional relational databases are more suitable for banking or accounting systems;

Traditional Business Intelligence applications: Data warehouse may be a more suitable choice for highly optimized query methods for specific problems;

SQL Problems

2. Deployment Environment

To build a high-availability MongoDB architecture, a Replica Set is required. It uses multiple Mongo services to ensure that one of the services fails, you can automatically switch to other services for failover, and these services are synchronized.

However, database applications with high data volume and throughput will put a lot of pressure on the performance of a single machine. A large amount of queries will consume the CPU of a single machine, and a large amount of data will put a lot of pressure on the storage of a single machine, eventually, the system memory will be exhausted and the pressure will be transferred to the disk IO. We can scale up devices vertically, such as adding more CPU and storage resources, but it is expensive. The Sharding cluster of MongoDB can be used to split data on multiple machines so that the database system can store and process more data to cope with the increasing load and data.

2.1 single-host

For the standalone environment, see the copy set node installation and configuration section.

2.2 replica set

A replica set is composed of a group of MongoDB instances with the same dataset. One of the nodes is the Primary node, and all write requests are completed on it. Other nodes are slave nodes, which receive and apply operations from the master node to ensure consistency with the dataset of the master node. A replica set can only have one master node. Once the master node is unavailable, the replica set will elect a slave node as the new master node.

The most basic replica set architecture consists of three members, and the number of members should be odd, including one master node (Primary) and one slave node (Secondary ), there is also a voting node (Arbiter ). The purpose of a voting node is only to participate in voting during the election process. The node does not contain datasets, so there are few resources required and no dedicated physical machine is required.

2.3 sharded Cluster

The sharded cluster includes the distribution route mongos, the configuration server config server, and the shard. The cluster architecture is as follows:

Mongos, the entry to cluster requests, distribute read/write requests to the shard server, and transparent access by front-end applications.

Config server stores the configuration of all database metadata (route and shard), and mongos loads configuration information from the configuration server. In the production environment, to ensure redundancy and security, three configuration servers are generally used and must be deployed on different machines.

Shard: a shard is a mongod or replica set that stores part of the data in the cluster. All the shard stores all the data in the cluster. In the production environment, to ensure a highly available sharding architecture, at least two shards must be ensured, and each shard should be a replica set. The replica set provides redundancy and high reliability for each shard.

3. Set up a replica set 3.1 install and configure a node

Note: perform the following configurations on the master node, slave node, and voting node!

3.1.1 Basic System Configuration
Disable SELinux # vi/etc/selinux/config ...... SELINUX = disabled ...... Disable firewall # service iptables stop # chkconfig iptables off restart machine # reboot
3.1.2 configure Time Synchronization
Install ntpdate # yum install-y ntpdate time synchronization # ntpdate pool.ntp.org set the scheduled task # crontab-e0 23 *** ntpdate pool.ntp.org>/var/log/ntpdate. log
3.1.3 install the software package
Install OpenSSL # yum install-y openssl-devel openssl to download and decompress the installation package, you can also copy the external download to the server root directory # wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.6.tgz # tar-zxvf mongodb-linux-x86_64-rhel62-3.0.6.tgz to move mongodb to the/usr/local/mongodb directory # mv mongodb-linux-x86_64-rhel62-3.0.6/usr/local/mongodb create data and log directory # mkdir/usr/local/mongodb/data # mkdir/usr/local/mongodb/log
3.1.4 configure services
Set automatic start upon startup, and add the startup information # vim/etc/rc. d/rc. local/usr/local/mongodb/bin/mongod -- fork -- auth -- dbpath/usr/local/mongodb/data -- logpath/usr/local/mongodb/log/mongodb. log -- replSet set0
Start the service #/usr/local/mongodb/bin/mongod -- fork -- auth -- dbpath/usr/local/mongodb/data -- logpath/usr/local/mongodb/log/mongodb. log -- replSet set0
3.2 configure replica set
Configure the replica set on the master node: Enter mongodb for configuration #. /bin/configure Config = {_ id: 'set0', members: [{_ id: 0, host: '123. 168.202.80 ', priority: 2}, {_ id: 1, host: '2017. 168.202.95 ', priority: 1}, {_ id: 2, host: '2017. 168.202.96 ', arbiterOnly: true}]} # enter the configuration information (the master server is the largest priority, and the voting node must be configured with arbiterOnly: true) for the configuration to take effect # rs. initiate (config)
3.3 installation Verification
Check the status. health indicates the status of the current service, and 1 indicates the normal status: # rs. status ()

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.