Install MongoDB 3.0 server on CentOS7

Source: Internet
Author: User
Tags install mongodb pdf manual

Install MongoDB 3.0 server on CentOS7
1. Download and install

MongoDB 3.0 official version released! This marks a new development stage for MongoDB databases, providing a powerful, flexible, and easy-to-manage database management system. MongoDB claims that the new version 3.0 not only improves the write efficiency by 7 to 10 times, but also increases the data compression rate by 80%, and reduces the O & M cost by 95%.
Main New Features of MongoDB 3.0 include:
· Pluggable storage engine APIs
· Support for the WiredTiger storage engine
· MMAPv1 Improvement
· Improved replica set
· Cluster Improvement
· Improved security
· Tool Improvement
The WiredTiger storage engine is an incredible technological implementation that provides no-door latches and non-blocking algorithms to leverage advanced hardware platforms (such as large-capacity chip caching and thread-based architecture) to improve performance. With WiredTiger, MongoDB 3.0 implements document-level concurrency control, which greatly improves the write load under high concurrency.

MongoDB provides centos yum installation.
Reference: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/
Pdf manual:
Http://docs.mongodb.org/manual/MongoDB-manual.pdf

Vi/etc/yum. repos. d/mongodb-org-3.0.repo

[mongodb-org-3.0]name=MongoDB Repositorybaseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/gpgcheck=0enabled=1

Install mongodb

yum install -y mongodb-org

All related services are installed.

......Running transaction  Installing : mongodb-org-shell-3.0.2-1.el7.x86_64      1/5   Installing : mongodb-org-tools-3.0.2-1.el7.x86_64      2/5   Installing : mongodb-org-mongos-3.0.2-1.el7.x86_64     3/5   Installing : mongodb-org-server-3.0.2-1.el7.x86_64     4/5   Installing : mongodb-org-3.0.2-1.el7.x86_64            5/5   Verifying  : mongodb-org-3.0.2-1.el7.x86_64           1/5   Verifying  : mongodb-org-server-3.0.2-1.el7.x86_64    2/5   Verifying  : mongodb-org-mongos-3.0.2-1.el7.x86_64    3/5   Verifying  : mongodb-org-tools-3.0.2-1.el7.x86_64     4/5   Verifying  : mongodb-org-shell-3.0.2-1.el7.x86_64     5/5

The configuration file is in the/etc/mongod. conf data file. the/var/lib/mongo log file is in the/var/log/mongodb service.

# Start service consumer d start # stop service consumer d stop # restart service consumer D restart # Add boot start chkconfig consumer D on
2. MongoDB CRUD

Reference: http://docs.mongodb.org/manual/core/crud-introduction/

Connect to MongoDB. It's easy to execute mongo.

# mongoMongoDB shell version: 3.0.2connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, see        http://docs.mongodb.org/Questions? Try the support group        http://groups.google.com/group/mongodb-userServer has startup warnings: 2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] 2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] ** WARNING: Readahead for /var/lib/mongo is set to 4096KB2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] **          http://dochub.mongodb.org/core/readahead2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] 2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] 2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] 2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] > 
2.1. Create data:

Http://docs.mongodb.org/manual/tutorial/insert-documents/ http://docs.mongodb.org/manual/reference/method/db.collection.insert/

> db.users.insert(... {... name:"zhang san",... age:26,... city:"bei jing"... }... )WriteResult({ "nInserted" : 1 })> db.users.insert(... {... _id:1,... name:"zhang san",... age:26,... city:"bei jing"... }... )WriteResult({ "nInserted" : 1 })> db.users.insert(... {... _id:1,... name:"zhang san",... age:26,... city:"bei jing"... }... )WriteResult({        "nInserted" : 0,        "writeError" : {                "code" : 11000,                "errmsg" : "E11000 duplicate key error index: test.users.$_id_ dup key: { : 1.0 }"        }})> db.users.insert(... {... _id:2,... name:"li si",... age:28,... city:"shang hai"... }... )WriteResult({ "nInserted" : 1 })

Data can have no primary key _ id. If not, one is automatically generated. If the _ id Primary Key is set, it must be unique. Otherwise, a primary key conflict is reported: "E11000 duplicate key error index: test. users. $ _ id _ dup key: {: 1.0 }"

2.2. Update Data:

Http://docs.mongodb.org/manual/tutorial/modify-documents/

> db.users.update(... {_id:2},... {... $set: {... city:"guang zhou"... }... }... )WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.users.update(... {_id:3},... {... $set: {... city:"si chuan"... }... },... { upsert: true }... )WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 3 })

Update is used for updates. If {upsert: true} is added, no data is queried and inserted directly.

2.3. Delete:

Http://docs.mongodb.org/manual/tutorial/remove-documents/

> db.users.remove({_id:3})WriteResult({ "nRemoved" : 1 })> db.users.remove({_id:4})WriteResult({ "nRemoved" : 0 })

Data is deleted only after query, and the number of deleted items is returned.

2.4. Query:

Http://docs.mongodb.org/manual/tutorial/query-documents/

> Db. users. find ({age: {$ gt: 26 }}) {"_ id": 2, "name": "li si", "age": 28, "city ": "guang zhou"}> db. users. find ({age: {$ gt: 25 }}) {"_ id": ObjectId ("5540adf29b0f52a6786de216"), "name": "zhang san", "age ": 26, "city": "bei jing"} {"_ id": 1, "name": "zhang san", "age": 26, "city ": "bei jing"} {"_ id": 2, "name": "li si", "age": 28, "city ": "guang zhou"} # query all data> db. users. find () {"_ id": ObjectId ("5540adf29b0f52a6786de216"), "name": "zhang san", "age": 26, "city ": "bei jing"} {"_ id": 1, "name": "zhang san", "age": 26, "city ": "bei jing"} {"_ id": 2, "name": "li si", "age": 28, "city": "guang zhou "}
2.5, more methods

Db. collection. aggregate () db. collection. count () db. collection. copyTo () db. collection. createIndex () db. collection. getIndexStats () db. collection. indexStats () db. collection. dataSize () db. collection. distinct () db. collection. drop () db. collection. dropIndex () db. collection. dropIndexes () db. collection. ensureIndex () db. collection. explain () db. collection. find () db. collection. findAndModify () db. collection. findOne () db. collection. getIndexes () db. collection. getShardDistribution () db. collection. getShardVersion () db. collection. group () db. collection. insert () db. collection. isCapped () db. collection. mapReduce () db. collection. reIndex () db. collection. remove () db. collection. renameCollection () db. collection. save () db. collection. stats () db. collection. storageSize () db. collection. totalSize () db. collection. totalIndexSize () db. collection. update () db. collection. validate ()

3. MongoDB visualization tool

Http://www.robomongo.org/

Use visualization tools to facilitate MongoDB management. First, modify the port and ip vi/etc/ipvd. conf.

port=27017dbpath=/var/lib/mongo# location of pidfilepidfilepath=/var/run/mongodb/mongod.pid# Listen to local interface only. Comment out to listen on all interfaces.bind_ip=192.168.1.36

Restart MongoDB

service mongod restart

Next, you can create a mongodb connection: after the connection is successful, the effect will be:

4. Summary

Link to the original article: http://blog.csdn.net/freewebsys/article/details/45366809. please refer to the source for more information!

MongoDB 3.0 is easy to operate. Efficient use. At the same time, the MongoDB extension is also very convenient. Next we will study. There is no complex join query for Internet businesses. Only the pursuit of efficient and fast access.

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.