• Home
  • Archive
  • Tools
  • Contact Us
  • Forum

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
The Customize Windows > Computer and Internet > Cloud Computing > How to Install, Configure, Secure MongoDB on Ubuntu 16.04 LTS

By Abhishek Ghosh November 24, 2017 8:17 am Updated on April 25, 2018

How to Install, Configure, Secure MongoDB on Ubuntu 16.04 LTS

Advertisement

MongoDB is a modern, lightweight, scalable NoSQL Database. MongoDB stores data as JSON-like documents and data structure can be changed over time. These are few points which makes MongoDB great choice for wider usage in data sciences to mobile application. Server with 512 MB RAM server is enough for basic testing purpose. Here is step by step guide on how to install, configure, secure MongoDB from SSH. For this guide, we are using Ubuntu 16.04 LTS as server operating system.

 

How to Install, Configure, Secure MongoDB

 

SSH to the intended server and become root. In case it is public server for long term use, definitely you should follow some steps like we described before in this article to secure the server.

First update, upgrade the instance :

Vim
1
2
apt update
apt upgrade

We have to add the key as next step :

Vim
1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

You’ll get this kind of correct response :

Vim
1
2
3
4
5
6
7
8
Executing: /tmp/tmp.B8ey1ENeI1/gpg.1.sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv
0C49F3730359A14518585931BC711F9BA15703C6
gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com
gpg: key A15703C6: public key "MongoDB 3.4 Release Signing Key <packaging@mongodb.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Next, we will add the repository at /etc/apt/sources.list.d/ with one line command :

Vim
1
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

Run update :

Vim
1
apt update

Install MongoDB :

Vim
1
apt install mongodb-org

We are installing community edition of MongoDB. MongoDB repository contains the following packages:

mongodb-org Is a metapackage that will automatically install the four component packages listed below.
mongodb-org-server Contains the mongod daemon and associated configuration and init scripts.
mongodb-org-mongos Contains the mongos daemon.
mongodb-org-shell Contains the mongo shell.
mongodb-org-tools Contains the following MongoDB tools: mongoimport bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop.

Run these two commands to check MongoDB started, running and enable on reboot :

Vim
1
2
3
4
sudo systemctl start mongod
sudo systemctl status mongod
# press q to quit
sudo systemctl enable mongod

If we run the command :

Vim
1
mongo

It starts MongoDB shell. If we run :

Vim
1
use admin

on that interface, we will become admin with this output :

Vim
1
switched to db admin

To create the user admin with password admin123 as admin run this :

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

Run :

Vim
1
exit

to exit. Now open /lib/systemd/system/mongod.service file :

Vim
1
nano /lib/systemd/system/mongod.service

Find the keyword ExecStart=. You’ll get the default line as :

Vim
1
ExecStart=/usr/bin/mongod --config /etc/mongod.conf

Advertisement

---

Change it to :

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

Save the file. Now, open this file :

Vim
1
nano /etc/mongod.conf

Find the keyword #security. Add this line at that place :

Vim
1
2
security:
  authorization: "enabled"

Run :

Vim
1
2
3
systemctl daemon-reload
# sudo service mongod restart
sudo systemctl restart mongod

Now, if we run the command :

Vim
1
mongo

It will not refuse. But, if you run command like show dbs, it will refuse with this kind of error :

Vim
1
2
3
4
5
6
2017-11-24T07:39:13.890+0000 E QUERY    [thread1] Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13,
"codeName" : "Unauthorized"
} :

To correctly login, we have to use this kind of command :

Vim
1
mongo -u admin -p admin123 --authenticationDatabase admin

Now if you run show dbs, you’ll get some valid response like :

Vim
1
2
admin  0.000GB
local  0.000GB

Run a cat on the settings file :

Vim
1
cat /etc/mongod.conf

You’ll notice lines like :

Vim
1
2
3
4
5
6
7
8
9
10
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
 
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

You can add IP of the current server beside 127.0.0.1 against bindIp separated with a comma. As my test server’s IP is 96.126.101.36, the config will be :

Vim
1
2
3
4
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1, 96.126.101.36

Run :

Vim
1
2
# sudo service mongod restart
sudo systemctl restart mongod

now, we can login with this kind of command :

Vim
1
2
mongo -u admin -p admin123 --authenticationDatabase admin --host 127.0.0.1
# mongo -u admin -p admin123 --authenticationDatabase admin --host 96.126.101.36

MongoDB supports TLS/SSL to encrypt all of MongoDB’s network traffic ensuring that MongoDB network traffic is only readable by the intended client. Normally we do not use TLS/SSL to avoid complexity.

To configure TLS/SSL go to :

Vim
1
cd /etc/ssl/

Generate a self-signed certificate with 365 days validity :

Vim
1
openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key

Above operation generates a new, self-signed certificate with no passphrase. Once you have the certificate, concatenate the certificate and private key to a .pem file:

Vim
1
cat mongodb-cert.key mongodb-cert.crt > mongodb.pem

Again, open this file we opened before :

Vim
1
nano /etc/mongod.conf

We only had :

Vim
1
2
3
4
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1, 96.126.101.36

We can add more settings :

Vim
1
2
3
4
5
6
net:
   port: 27017
   bindIp: 127.0.0.1, 96.126.101.36
   ssl:
      mode: requireSSL
      PEMKeyFile: /etc/ssl/mongodb.pem

How to Install, Configure, Secure MongoDB on Ubuntu 16-04 LTS

Save the file. Run :

Vim
1
2
# sudo service mongod restart
sudo systemctl restart mongod

You’ll get detailed information on SSL/TLS configuration and also commands to login :

Vim
1
https://docs.mongodb.com/manual/tutorial/configure-ssl-clients/

Tagged With how to setup ssh for mongodb on windows

This Article Has Been Shared 5487 Times!

Facebook Twitter Google+ Pinterest

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Orthopaedic Surgeon, Author and Blogger. You can keep touch with him on Google Plus - Abhishek Ghosh1 and on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to How to Install, Configure, Secure MongoDB on Ubuntu 16.04 LTS

  • WordPress XML-RPC Attack & Fake PHP5-FPM Error

    WordPress XML-RPC Attack Can Bring DDoS Resulting in Random 502 PHP5-FPM Errors on Nginx Server or Can Make the Database Down. Here is Fix.

  • Setup SFTP Without Shell Access For WordPress, Cloud Server

    Often We Need To Host Account On VPS OR Cloud Server Where It Is Desired To Have A Setup SFTP Without Shell Access For WordPress Like cPanel.

  • Create Data Science Environment on Cloud Server With Docker

    Here Are the Steps, Commands to Create Data Science Environment on Cloud Server For Data Analysis Starting With a Blank Server With SSH.

  • How to Install and Set Up LXD on Ubuntu 16.04

    Here is How to Install and Set Up LXD on Ubuntu 16.04. LXD Works With a Directory Based Storage Backend. LXD is lxc with strong security.

  • HP Will Not Sell Cheap Cloud Servers To Amazon Like Companies

    Hewlett Packard Enterprise Will Not Sell Cheap Cloud Servers To Amazon Like Companies Who Order Building Servers at China To Save Dual Loss.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Google+ or Twitter to join the conversation right now!

If you want to Advertise on our Article or want Business Partnership, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

You can subscribe to our Free Once a Day, Regular Newsletter by clicking the subscribe button below.

Click To Subscribe Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Google+ (13.7k Followers)
  • Pinterest (11.4K Followers)
  • Twitter (4.7k Followers)
  • Facebook (4.9k Followers)
  • LinkedIn (3.2k Followers)
  • YouTube (1.5k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Getting Started With IBM Cloud IoT (Watson IoT Platform) February 22, 2019
  • ESP WROOM 32 : How To Setup ESP32 NodeMCU With Arduino IDE February 21, 2019
  • Arduino, NodeMCU ECG : AD8232 Single Lead ECG Module February 21, 2019
  • WiFi With Arduino For IoT : ESP8266, ESP32, NodeMCU, Adafruit Feather February 20, 2019
  • Wearables and Internet of Things : Part II February 13, 2019

About This Article

Title: How to Install, Configure, Secure MongoDB on Ubuntu 16.04 LTS
2017-11-24

Author: Abhishek Ghosh
Subjects: Cloud Computing

Is Part Of:


TheCustomizeWindows,

Friday, November 24th, 2017,
Vol.1(01),
p.1–54309 [IoT Ready Journal]


Source:The Customize Windows
ISSN: 0019-5847 ;
E-ISSN: 0019-5847 ;
Publisher:
jima.in

Cite this article as: Abhishek Ghosh, "How to Install, Configure, Secure MongoDB on Ubuntu 16.04 LTS," in The Customize Windows, November 24, 2017, February 22, 2019, https://thecustomizewindows.com/2017/11/how-to-install-configure-secure-mongodb-on-ubuntu-16-04-lts/.

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Cookie Policy.


PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

web analysis

Copyright © 2019 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy