In-depth understanding of MongoDB (i) Linux configuration MongoDB all Raiders

Source: Internet
Author: User
Tags create mongodb mongodb server pkill value store

a MongoDB introduction

MongoDB is a high-performance, open-source, modeless document-based database that is a popular one in the current NoSQL database. It can be used in many scenarios to replace a traditional relational database or key/value store, MONGO using C + + development. MONGO's official website address is: http://www.mongodb.org/, where readers can get more detailed information.

Characteristics:

It is characterized by high performance, easy to deploy, easy to use, and easy to store data. The main features are:
    • for collection storage, easy to store data for object types.
    • mode free.
    • support dynamic queries.
    • full index supported, containing internal objects.
    • support query.
    • support replication and recovery.
    • use efficient binary data storage, including large objects such as video.
    • support ruby,python,java,c++,php,c# and many more languages.
    • accessible over the network.

Function:

    • Collection-oriented storage: suitable for storing objects and data in JSON form.
    • Dynamic query: MONGO supports rich query expressions. Query directives use a JSON-style tag to easily query objects and arrays embedded in the document.
    • Full index support: Includes embedded objects and arrays in the document. The query optimizer of MONGO parses the query expression and generates an efficient query plan.
    • Query monitoring: MONGO contains a monitoring tool to analyze the performance of database operations.
    • Replication and automatic failover: The MONGO database supports data replication between servers, supporting master-slave mode and inter-server replication. The primary goal of replication is to provide redundancy and automatic failover.
    • Efficient traditional storage: supports binary data and large objects (such as photos or pictures)
    • Auto-sharding to support cloud-scale scalability: Automatic sharding supports a level of database clustering, adding additional machines dynamically.

Applicable scenarios:

    • Website real-time data processing. It is ideal for real-time inserts, updates and queries, as well as the replication and high scalability required for real-time data storage on the site.
    • Cache. Because of its high performance, it is suitable as a caching layer for the information infrastructure. After the system restarts, the persistent cache layer built by it can avoid overloading the underlying data sources.
    • High-scalability scenarios. Ideally suited to a database of dozens of or hundreds of servers, its roadmap already includes built-in support for the MapReduce engine.


Scenario Not applicable:

    • Requires a highly transactional system.
    • Traditional business intelligence applications.
    • Complex cross-document (table) cascading queries.

two MongoDB configuration full guide

Release Notes:

redhat:6.1 x86_64

mongodb:2.6.3

First, we go to the official website (http://www.mongodb.org/downloads) to download 64-bit Linux version of MongoDB;

Then, do the preparation before configuring MongoDB;

--Create MongoDB home directory  # mkdir/usr/local/mongodb/  --unzip the MongoDB package to the MongoDB home directory  # TAR-XVF Mongodb-linux-x86_64-2.6.3.tgz-c/usr/local/mongodb/ --create MongoDB Data directory, Can be stored in other locations, such as RAID, LVM  # mkdir/usr/local/mongodb/data/ --Create the MongoDB log directory, it is recommended to put in the Var directory  # mkdir/usr/local/mongodb/log/ 

Next, we use the Mongod command to start MongoDB, and then open another terminal, using the MONGO command to connect to MongoDB;

# cd/usr/local/mongodb/bin/#./mongod--dbpath=/usr/local/mongodb/data/--logpath=/usr/local/mongodb/log/mongo.log #./mongomongodb Shell version:2.6.3connecting to:test>

Next, configure the environment variables;

# pwd/usr/local/mongodb/bin# Vim ~/.bash_profile # TAIL-N3! $tail-n3 ~/.bash_profilepath= $PATH: $HOME/bin:/usr/local/ Mongodb/binexport path# Source! $source ~/.bash_profile

To make it easier to start and close MongoDB, we can use the shell to write scripts, of course, can also be added to the service;

# cp ssh mongodb# vim mongodb# cat mongodb#!/bin/bash## mongodstart up the MongoDB server daemon## source function lib Rary. /etc/rc.d/init.d/functions#定义命令 cmd=/usr/local/mongodb/bin/mongod#定义数据目录  Dbpath=/usr/local/mongodb/data#定义日志目录 logpath=/usr/local/mongodb/log/mongo.logstart () { #fork表示后台运行 $CMD--dbpath= $DBPATH--logpath= $LOGPATH--forkecho "MongoDB is running background ..."}stop () {Pkill Mongodecho " MongoDB is stopped. "} Case "$" instart) start; stop) stop;; *) echo $ "Usage: $ start|stop}" Esac

We can test the correctness of writing scripts;

#/etc/init.d/mongodb Startabout to fork child process, waiting until server was ready for connections.forked process:1347 Child process started successfully, parent Exitingmongodb is running background...#/etc/init.d/mongodb stopterminated

Of course, the better way is to use the configuration file, the parameters MongoDB needs to write to the configuration file, and then referenced in the script;

#代表端口号, the default is 27017 if not specified #port =27027 #MongoDB数据文件目录 Dbpath=/usr/local/mongodb/data #MongoDB日志文件目录 Logpath=/usr/local/mongodb/log/mongo.log #日志文件自动累加 logappend=true

After writing the configuration file, we need to modify the startup script;

# vim MongoDB # cat MongoDB #!/bin/bash## mongodstart up the MongoDB server daemon## source function library./etc/rc. D/init.d/functions#定义命令 cmd=/usr/local/mongodb/bin/mongod#定义配置文件路径 initfile= /usr/local/mongodb/mongodb.confstart () {#& indicates background startup, you can also use the fork parameter $CMD-F $INITFILE &echo " MongoDB is running background ... "}stop () {pkill Mongodecho" MongoDB is stopped. "} Case "$" instart) start; stop) stop;; *) echo $ "Usage: $ start|stop}" Esac

Once the writing is complete, test the script again for correctness.

[Email protected] init.d]#/etc/init.d/mongodb Startmongodb is running background ... [Email protected] init.d]#/etc/init.d/mongodb stopterminated


three PostScript

This is the first article in-depth understanding of MongoDB, this article briefly introduces MongoDB and presents the complete configuration process for Linux to the reader.

Four references

Http://baike.baidu.com/subview/3385614/9338179.htm


Good luck!

Robin

August 2, 2014

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.