How to Install MongoDB 3.2 on Ubuntu 16.04, 14.04, 12.04 and Debian 8/7

2016年11月24日

MongoDB (named from “huMONGOus“) is a full flexible index support and rich queries database. Its is a NoSQL database. MongoDB provides large media storage with GridFS. MongoDB 3.2 introduces new storage engines that extend the capabilities of the database. Click here for more details about this version of MongoDB.

install mongodb

This tutorial will help you to install MongoDB 3.2 Production Release on Ubuntu 16.04 LTS (Xenial) 14.04 LTS (trusty), 12.04 LTS (precise) and Debian 8 and 7 systems.

Adding Apt Repository

First import public key of MongoDB apt repository in our system using following command.

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

Lets add MongoDB APT repository url in /etc/apt/sources.list.d/mongodb.list.

For Ubuntu:
$ echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb.list
For Debian:
$ echo "deb http://repo.mongodb.org/apt/debian "$(lsb_release -sc)"/mongodb-org/3.2 main" | sudo tee /etc/apt/sources.list.d/mongodb.list

Install MongoDB

After adding required APT repositories, use following commands to install MongoDB in your systems. It will also install all dependent packages required for mongodb.

$ sudo apt-get update
$ sudo apt-get install mongodb-org

If you want to install any specific version of MontoDB, define the version number like below

$ apt-get install mongodb-org=3.2.0 mongodb-org-server=3.2.0 mongodb-org-shell=3.2.0 mongodb-org-mongos=3.2.0 mongodb-org-tools=3.2.0

Start MongoDB Service

After installation MongoDB will start automatically. To start or stop MongoDB use init script. Below are the example commands to do.

$ sudo service mongod start
$ sudo service mongod stop

Verify MongoDB Installation

Finally use the below command to check installed MongoDB version on your system.

ubuntu@tecadmin:~$ mongod --version 

db version v3.2.0
git version: 45d947729a0315accb6d4f15a6b06be6d9c19fe7
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1404
    distarch: x86_64
    target_arch: x86_64

[root@debian8-erp ~]# mongo
MongoDB shell version: 3.2.11
connecting to: test
Welcome 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-user
Server has startup warnings:
2016-11-23T19:41:42.668-0800 I CONTROL  [initandlisten]
2016-11-23T19:41:42.668-0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-11-23T19:41:42.668-0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-11-23T19:41:42.668-0800 I CONTROL  [initandlisten]

> exit
echo never > /sys/kernel/mm/transparent_hugepage/defrag
service  mongod restart 

Also connect MongoDB using command line and execute some test commands for checking proper working.

ubuntu@tecadmin:~$ mongo

> use mydb;

> db.test.save( { tecadmin: 100 } )

> db.test.find()

  { "_id" : ObjectId("52b0dc8285f8a8071cbb5daf"), "tecadmin" : 100 }

没有评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注