Friday, March 9, 2018

How to Install MongoDB 3.x on Ubuntu 16.04 LTS

MongoDB:
MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. MongoDB obviates the need for an Object Relational Mapping (ORM) to facilitate development.

Record:

A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.


Collection:
MongoDB stores documents in collections. Collections are analogous to tables in relational databases. Unlike a table, however, a collection does not require its documents to have the same schema.

In MongoDB, documents stored in a collection must have a unique _id field that acts as a
 primary key


Packages: 

MongoDB provides officially supported packages in their own repository. This repository contains the following packages:
Package NameDescription
mongodb-orgmetapackage that will automatically install the four component packages listed below.
mongodb-org-serverContains the mongod daemon and associated configuration and init scripts.
mongodb-org-mongosContains the mongos daemon.
mongodb-org-shellContains the mongo shell.
mongodb-org-toolsContains the following MongoDB tools: mongoimport bsondumpmongodumpmongoexportmongofilesmongoperfmongorestoremongostat, and mongotop.
Installation:


he mongodb-org-server package provides an initialization script that starts mongod with the /etc/mongod.conf configuration file

etc/mongod.conf configuration file supplied by the packages have bind_ip set to 127.0.0.1 by default. Modify this setting as needed for your environment.


Step 1: Import the Public key
root@US16:~# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
Step 2: Create a list file for MongoDB.
Create the /etc/apt/sources.list.d/mongodb-org-3.6.list list file using the command 
root@US16:~# echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
Step 3:  Update Package Database
root@US16:~# apt update
Step 4: Install MongoDB Package
To install MongoDB latest version run the following command.
root@US16:~# apt-get install -y mongodb-org

To install a specific release, you must specify each component package individually along with the version number, as in the following example:

root@US16:~# apt-get install -y mongodb-org=3.6.0 mongodb-org-server=3.6.0 mongodb-org-shell=3.6.0 mongodb-org-mongos=3.6.0 mongodb-org-tools=3.6.0
Installation of Mongodb version 3.6.0 has done.
Step 5: Start Mongodb service.
To start Mongodb service hit the following command
root@US16:~# systemctl start mongod.service
Check Service status
root@US16:~# systemctl status mongod.service
Mongodb server is up and running.
Step 6: Enable mongodb service auto start at system boot.
root@US16:~# systemctl enable mongod.service
Step 7: Check Mongodb version
root@US16:~# mongo -version

Mongodb server installation has completed, in next blog We will learn some basic command to administrate mongodb server.


To enable logon authentication, Please visit URL below:




3 comments: