MongoDB installation and multi-instance startup

Source: Internet
Author: User
Tags chmod create mongodb install mongodb install openssl mkdir openssl file permissions server port


MongoDB installation and multi-instance start MongoDB Introduction


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.



In the age of big data, the processing of large data volumes has become one of the most important reasons to consider a database. One of the main goals of MongoDB is to keep the database as excellent as possible, which largely determines the design of MongoDB. MongoDB chooses to maximize its use of memory resources as a cache for superior performance, and automatically selects the fastest index for querying. MongoDB is one of the reasons why MongoDB can maintain superior performance by streamlining the database as much as possible and handing over as many operations as possible to the client.



MongoDB is the most versatile non-relational database (NoSQL), most like a relational database. Without a relational model for better extensibility, MongoDB does not have a "line" concept, and it works primarily on two concepts: Collections (collection) and documents.


Features of MongoDB


MONGO is a high-performance, open-source, modeless, document-based database that can be used in many scenarios to replace traditional relational databases or key/value storage methods.



1. Collection-oriented storage: suitable for storing objects and data in JSON form.



2, the MongoDB installation is simple, provides the document-oriented storage function, the operation is relatively easy.



3. 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.



4. MongoDB supports rich query expressions.



5, efficient traditional storage: support binary data and large objects (such as photos or pictures).


MongoDB Areas of Application


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


MongoDB installation 1, download and install MongoDB and support software.


We chose to download the package directly, because the virtual machine I use is CentOS7 and is a 64-bit version, so we choose the corresponding REDHAT7 version 64-bit. After downloading, the configuration can be used directly. Because the package has SSL secure encryption enabled, we need to install the OpenSSL dependent package.


[root@promote ~]# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.0.tgz
# can download directly
[root@promote ~]# yum install openssl openssl-devel -y
#Install related dependencies
[root@promote ~]# tar xvfz mongodb-linux-x86_64-rhel70-4.0.0.tgz -C /usr/local/
#Unzip the archive to the specified directory
[root@promote ~]# mv /usr/local/mongodb-linux-x86_64-rhel70-4.0.0/ /usr/local/mongodb
#Rename the package for future use
2. Create data store directory, log storage directory and log file


Since we are downloading a compiled package, we need to create our own data store directory, log storage log and log file.


[root@promote ~]# mkdir -p /data/mongodb1
#Create data storage directory
[root@promote ~]# mkdir -p /data/logs/mongodb
#Create a log storage directory
[root@promote ~]# touch /data/logs/mongodb/mongodb1.log
#Create a log file
[root@promote ~]# chmod -R 777 /data/logs/mongodb/mongodb1.log
#Modify log file permissions, convenient for the following operations


When MongoDB is in a state of frequent access, if the shell startup process consumes a resource set too low, it will generate an error to be unable to connect to MongoDB.


[root@promote ~]# ulimit -n 2500 #Modify the maximum number of processes that the shell can enable
[root@promote ~]# ulimit -u 2500 #Modify the maximum number of files that the shell can open.
3. Create MongoDB profile and configure startup parameters


The downloaded package does not have a configuration file and we need to create it ourselves.


[root@promote ~]# cd /usr/local/mongodb/bin/
[root@promote bin]# vim mongodb1.conf
Port=27017 #default server port number
Dbpath=/data/mongodb1 #Data storage directory, which we created in the previous step
Logpath=/data/logs/mongodb/mongodb1.log #log file
Logappend=true #Write the log using append mode
Fork=true #background running
maxConns=5000 #Maximum number of connections
4. Start and stop MongoDB


The MongoDB service that can be started after the installation and configuration is ready.


[root@promote bin]# export PATH=$PATH:/usr/local/mongodb/bin/
# can add the path of MongoDB to the environment variable, so you can directly use the relevant commands of MongoDB
[root@promote bin]# mongod -f /usr/local/mongodb/bin/mongodb1.conf
#mongod is used to start the service process, and -f is followed by the configuration file path of the service.
[root@promote bin]# netstat -ntap | grep mongod #View MongoDB process startup status
Tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 78984/mongo
[root@promote bin]# mongo # can enter the database

[root@promote bin]# mongod -f /usr/local/mongodb/bin/mongodb1.conf --shutdown
#--shutdown means to close the MongoDB service process.
2018-07-16T21:22:05.828+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none‘
Killing process with pid: 78984
[root@promote bin]# netstat -ntap | grep mongod #No MongoDB process
Start a MongoDB multi-instance


With sufficient resources for a single server, multiple instances can be used to make full use of server resources. Steps are the same as above, creating a set of data store directories, log files, and configuration files.


[root@promote bin]# mkdir -p /data/mongodb2
#Create a new data storage directory
[root@promote bin]# touch /data/logs/mongodb/mongodb2.log
#Create a new log file
[root@promote bin]# chmod -R 777 /data/logs/mongodb/mongodb2.log
#Assign the corresponding permissions of the log file
[root@promote bin]# chmod -R 777 /data/logs/mongodb/mongodb2.log
[root@promote bin]# cp /usr/local/mongodb/bin/mongodb1.conf /usr/local/mongodb/bin/mongodb2.conf
#Copy a new configuration file and modify the corresponding parameters
Port=27018 #Set a new port number
Dbpath=/data/mongodb2 #Set up a new data storage directory
Logpath=/data/logs/mongodb/mongodb2.log #Set up a new log file
Logappend=true
Fork=true
maxConns=5000

[root@promote bin]# mongod -f /usr/local/mongodb/bin/mongodb2.conf #Open the process of the new instance
[root@promote bin]# mongod -f /usr/local/mongodb/bin/mongodb1.conf
2018-07-16T21:31:16.103+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none‘
About to fork child process, waiting until server is ready for connections.
Forked process: 79334
Child process started successfully, parent exiting
[root@promote bin]# netstat -ntap | grep mongo
Tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 79334/mongod
Tcp 0 0 127.0.0.1:27018 0.0.0.0:* LISTEN 79304/mongod
# can see that two instances are open 


MongoDB installation and multi-instance startup


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.