How To Install and Configure MongoDB On Ubuntu

How To Install and Configure MongoDB On Ubuntu

We can install and configure the MongoDB database server on ubuntu. MongoDB is an open-source cross-platform document-oriented database program also known as the NoSQL database. It uses the JSON like document schema. we can also install MongoDB in Linux as well. 

Check Out: How To Create Elastic File System(EFS) On Amazon Cloud

Update the current packages with sudo apt update.

Once it’s finished, install the MongoDB using the below command.

sudo apt install mongodb mongodb-client

you can check the MongoDB version using mongo command.

root@ubuntu:~# mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3

Let’s check the services and enable them at boot time using the following commands.

systemctl status mongodb
root@ubuntu:~# systemctl status mongodb
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-03-22 12:57:59 UTC; 6min ago
Docs: man:mongod(1)
Main PID: 3249 (mongod)
Tasks: 24 (limit: 2290)
CGroup: /system.slice/mongodb.service
└─3249 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

Mar 22 12:57:59 ubuntu systemd[1]: Started An object/document-oriented database.

we can enable and disable MongoDB service using systemctl enable mongodb && systemctl disable mongodb

if you want to stop service using this command systemctl stop mongodb

Check Out: Enable and Disable Journaling On EXT4 File Systems In Linux

Check the firewall status and allow the MongoDB port in the rules. so

root@ubuntu:~# ufw status
Status: inactive

Enable the firewall using ufw enable

root@ubuntu:~# ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup

to check the status so

root@ubuntu:~# ufw status
Status: active

MongoDB uses port number 27017 and we need to allow the port in the firewall rules. so

root@ubuntu:~# ufw allow from 192.168.0.0/32 to any port 27017
Rule added

Check Out: How To Install Node.js And NPM On Ubuntu 19.04

check the status of the rule on the ubuntu firewall. so

root@ubuntu:~# ufw status 
Status: active

To                        Action                     From
--                       ------                      ----
27017                     ALLOW                    192.168.0.0

Bind Ip in the configuration file vim /etc/mongodb.conf

logappend=true

bind_ip = 127.0.0.1, 192.168.185.137
#port = 27017

Restart the service so

systemctl restart mongodb

we can check the port should be listening on 27017 using the command so

netstat -tnlp | grep mongod
root@ubuntu:~# netstat -tnlp | grep mongod
tcp     0     0   127.0.0.1:27017     0.0.0.0:*     LISTEN    3749/mongod

You’re done install mongodb linux

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment