MongoDB installation Configuration notes in CentOS 6.4 system

Source: Internet
Author: User
Tags arrays curl failover json mkdir mongodb centos

First, what is MongoDB?

MongoDB is a document-oriented database system that is different from the relational database MySQL we normally use. He writes with C + +, does not support SQL, but has its own powerful query syntax. MongoDB uses Bson as the format for data storage and transmission. Bson is a JSON-like binary serialization document that supports nested objects and arrays. MongoDB is much like mysql,document corresponding to MySQL's row,collection corresponding to MySQL table. Is the most popular one in the current NoSQL database. It can be used to replace traditional relational database or key/value storage in many scenarios.


II. Logical Structure of data

MongoDB documents document corresponds to a row of records in the relational database.

Multiple Documents form a collection collection The table that corresponds to a relational database.

Multiple collections collection logically organized together are database databases.

A MongoDB instance supports multiple database databases.

The hierarchy of documents (document), Collections (collection), databases (database) is shown below:


third, MongoDB characteristics

High-performance, easy to deploy, easy to use, storage data is very convenient.

For collection-oriented storage, it is easy to store data of object types.

Mode of freedom.

Supports dynamic queries.

Supports full indexing, containing internal objects.

Support for replication and recovery.

Use efficient binary data storage, including large objects such as video.

Automatically handles fragmentation to support cloud level scalability

Supports drivers for Python,php,ruby,java,c,c#,javascript,perl and C + + languages.

The file storage format is Bson (an extension of JSON).

can be accessed over the network.

Four, MongoDB function

Collection-oriented storage: data that is appropriate for storing objects and JSON forms.

Dynamic query: MONGO supports rich query expressions. Query directives use JSON-form tags to easily query objects and arrays that are embedded in the document.

Full index support: Includes document inline objects and arrays. The MONGO query optimizer analyzes the query expression and generates an efficient query plan.

Query monitoring: MONGO contains a monitoring tool for analyzing the performance of database operations.

Replication and automatic failover: The MONGO database supports data replication between servers, supporting master-from-mode and server replication. The primary goal of replication is to provide redundancy and automatic failover.

Efficient traditional storage: support for binary data and large objects (such as photos or pictures)

Automatic fragmentation to support cloud-level scalability: automatic fragmentation supports a level of database clustering that can dynamically add additional machines.

Applicable occasions:

Site data: MONGO 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 Web site.

Caching: Because of its high performance, MONGO is also suitable as a caching layer for the information infrastructure. After the system restarts, the persistent cache layer built by MONGO can avoid overloading the underlying data source.

Large size, low value data: It may be expensive to store some data using a traditional relational database, before which programmers often choose traditional files for storage.

Highly scalable scenario: MONGO is ideal for databases composed of dozens of or hundreds of servers. The MONGO roadmap already contains built-in support for the MapReduce engine.

Storage for objects and JSON data: MONGO's Bson data format is ideal for storing and querying in a documented format.


To friends who are accustomed to relational databases. I compare MongoDB with the logical structure of relational database

So that we can have a deeper understanding of MongoDB's logical structure.


attached to my test centos6.4 installation notes:

The code is as follows Copy Code

Mkdir-p/usr/local/mongodb/data
Mkdir/usr/local/mongodb/log
Mkdir/usr/local/mongodb/source

Useradd-m-s/sbin/nologin MongoDB
Chown-r Mongodb.mongodb/usr/local/mongodb


Cd/usr/local/mongodb/source
Curl-o http://pecl.php.net/get/mongo-1.2.4.tgz
Curl-o http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.9.tgz
TAR-ZXVF mongo-1.2.4.tgz; TAR-ZXVF mongodb-linux-x86_64-2.0.9.tgz


cd/usr/local/mongodb/mongo-1.2.4/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make; Make install


See if the mongo.so is copied to the PHP extended directory and not replicated.

  code is as follows copy code

#复制 mongo.so to PHP's extended directory
CP modules/mongo.so/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626


#更改配置文件
Vi/usr/local/php/etc/php.ini
Add extension=mongo.so


CD mongodb-linux-x86_64-2.0.9
MV Bin/. /.. /bin


#启动Mongodb服务
/usr/local/mongodb/bin/mongod--dbpath=/usr/local/mongodb/data/--fork
--logpath=/usr/local/mongodb/log/mongodb.log--logappend&
More Settings in detail:
/usr/local/mongodb/bin/mongod--fork--dbpath/usr/local/mongodb/data/
--logpath/usr/local/mongodb/log/mongodb.log--maxconns 1000--directoryperdb
--auth--quiet--logappend &


#终端出现waiting for connections on port 27017
#查看服务是否开启成功
Netstat-ntl | grep 27017


Reboot your Web server or PHP-FPM, print phpinfo, and if you see the MONGO Item table, then MongoDB's extended installation is successful.


At last:
Add CentOS Boot entry

The code is as follows Copy Code
[root@localhost]# vi/etc/rc.d/rc.local

Append the MongoDB startup command to this file:

The code is as follows Copy Code
/usr/local/mongodb/bin/mongod--dbpath=/usr/local/mongodb/data
--logpath/usr/local/mongodb/logs/log.log-fork


It is recommended to use Rockmongo for management MongoDB

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.