banner



How To Install Mongodb On Ubuntu 16

There is a new version of this tutorial available for Ubuntu 20.04 (Focal Fossa).

How to Install and Configure MongoDB on Ubuntu 16.04 LTS

This tutorial exists for these OS versions

  • Ubuntu 20.04 (Focal Fossa)
  • Ubuntu eighteen.04 (Bionic Beaver)
  • Ubuntu xvi.04 (Xenial Xerus)
  • Ubuntu fourteen.04 LTS (Trusty Tahr)

On this page

  1. Prerequisites
  2. Install MongoDB on Ubuntu 16.04
    1. Stride 1 - Importing the Public Cardinal
    2. Step 2 - Create source list file MongoDB
    3. Step 3 - Update the repository
    4. Step four - Install MongoDB
  3. Configure MongoDB username and password
    1. Step 1 - Open mongo shell
    2. Step 2 - Switch to the database admin
    3. Step three - Create the root user
    4. Step 4 - Enable mongodb authentication
    5. Step 5 - Restart MongoDB and attempt to connect
  4. Conclusion

MongoDB is a NoSQL database that offers a high performance, high availability, and automatic scaling enterprise database. MongoDB is a NoSQL database, so you can't use SQL (Structured Query Linguistic communication) to insert and recollect data, and it does non shop information in tables like MySQL or Postgres. Information is stored in a "document" structure in JSON format (in MongoDB chosen BSON). MongoDB was showtime introduced in 2009 and is currently adult past the company MongoDB Inc.

" MongoDB only provides packages for 64-bit LTS (long-term support) Ubuntu releases. For example, 12.04 LTS (precise), 14.04 LTS (trusty), 16.04 LTS (xenial), and then on. " mongodb site.

Prerequisites

  • Ubuntu Server 16.04 - 64 scrap
  • Root privileges

What we will do in this tutorial:

  1. Install MongoDB
  2. Configure MongoDB
  3. Conclusion

Install MongoDB on Ubuntu 16.04

Stride 1 - Importing the Public Key

GPG keys of the software distributor are required by the Ubuntu package manager apt (Avant-garde Parcel Tool) to ensure package consistency and authenticity. Run this control to import MongoDB keys to your server.

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

Step 2 - Create source list file MongoDB

Create a MongoDB list file in /etc/apt/sources.listing.d/ with this control:

                echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/three.ii multiverse" | sudo tee /etc/apt/sources.listing.d/mongodb-org-3.ii.list              

Step 3 - Update the repository

update the repository with the apt command:

sudo apt-get update

Step 4 - Install MongoDB

At present you can install MongoDB by typing this command:

sudo apt-get install -y mongodb-org

Nosotros have to create a new MongoDB systemd service file in the '/lib/systemd/system' directory. Go to that directory and create the new MongoDB service file 'mongod.service' with vim editor.

cd /lib/systemd/arrangement/
vim mongod.service

Paste script below:

[Unit]
Description=High-performance, schema-free document-oriented database
Subsequently=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

Relieve the file and exit.

Now update the systemd service with the control below:

systemctl daemon-reload

Start MongoDB and add it every bit a service to be started at kicking fourth dimension:

systemctl commencement mongod
systemctl enable mongod

At present check that MongoDB has been started on port 27017 with the netstat command.

netstat -plntu

Check if MongoDB is running.

Configure MongoDB username and countersign

When the MongoDB packages are installed y'all can configure username and password for the database server:

Pace ane - Open up mongo shell

Before you set upwards a username and countersign for MongoDB, you need to open the MongoDB crush on your server. You tin can login by typing:

mongo

If yous become error Failed global initialization: BadValue Invalid or no user locale prepare. Please ensure LANG and/or LC_* environment variables are set correctly, attempt the command:

export LC_ALL=C
mongo

Step 2 - Switch to the database admin

Once you`re in the MongoDB beat out, switch to the database named admin:

use admin

Pace 3 - Create the root user

Create the root user with this control :

db.createUser({user:"admin", pwd:"admin123", roles:[{part:"root", db:"admin"}]})

Desc: Create user admin with password admin123 and accept the permission/office as root and the database is admin.

Create a admin user in MongoDB

At present type exit to get out from MongoDB shell.

Step 4 - Enable mongodb hallmark

Edit the mongodb service file '/lib/systemd/organisation/mongod.service' with your editor. Advertisement

vim /lib/systemd/system/mongod.service

On the 'ExecStart' line nine, add together the new option '--auth'.

ExecStart=/usr/bin/mongod --quiet --auth --config /etc/mongod.conf

Relieve the service file and exit vim.

Reload the systemd service:

systemd daemon-reload

Step 5 - Restart MongoDB and endeavour to connect

Now restart MongoDB and connect with the user created.

sudo service mongod restart

and connect to the MongoDB shell with this control:

mongo -u admin -p admin123 --authenticationDatabase admin

and yous will encounter the output like this:

Test MongoDB Authentication.

Conclusion

A well-known NoSQL database that offers high operation, loftier availability, and automated scaling is MongoDB. It is different from the RDBMS such as MySQL, PostgreSQL, and SQLite as it does not use SQL to fix and call up information. MongoDB stores information in `documents` called BSON (binary representation of JSON with additional types of data). MongoDB is only available for 64-bit Long Term Support Ubuntu Release.

Suggested articles

Source: https://www.howtoforge.com/tutorial/install-mongodb-on-ubuntu-16.04/

Posted by: rinconwhought.blogspot.com

0 Response to "How To Install Mongodb On Ubuntu 16"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel