How To Install MongoDB 4 on Debian 10 (Buster)

Posted on 221 views

How can I install MongoDB 4 on Debian 10 (Buster)?. MongoDB is an open source NoSQL database written in C++ for massive scalability, high performance, and availability. As of this article update, the repositories available are for Debian 9. We will add some hacks to Install MongoDB 4 on Debian 10 (Buster). But once the repository is available for Debian 10, this article will be updated.

Here are the steps you’ll need to Install MongoDB 4 on Debian 10 (Buster). I’m doing this setup on a fresh minimal installation of Debian 10 server. This is recommended to ensure you don’t break running applications dependencies.

Step 1: Add MongoDB repository

Import MongoDB GPG Key

sudo apt update
sudo apt -y install gnupg2
wget -qO - | sudo apt-key add -

Then add repository URL to your Debian system.

echo "deb buster/mongodb-org/4.4 main" | sudo tee /etc/apt/sources.list.d/mongodb-org.list

Step 2: Install MongoDB Server on Debian 10 (Stretch)

We have added required repositories and installed libcurl3. Let’s now install MongoDB on Debian 10 (Stretch).

sudo apt update
sudo apt -y install mongodb-org

Get package information with apt info command.

$ apt info mongodb-org
Package: mongodb-org
Version: 4.4.8
Priority: optional
Section: database
Maintainer: Ernie Hershey [email protected]
Installed-Size: 13.3 kB

The installation of the above package will install the following dependency packages:

mongodb-org-server – This provides MongoDB daemon mongod
mongodb-org-mongos – This is a MongoDB Shard daemon
mongodb-org-shell – This provides a shell to MongoDB
mongodb-org-tools – MongoDB tools used for export, dump, import e.t.c

Step 3: Start MongoDB Server on Debian 10 (Stretch)

The server daemon is named mongod. Start and set it to start on server reboot/boot up.

sudo systemctl enable --now mongod

Check its running status.

$ systemctl status  mongod.service
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-08-22 23:40:54 CEST; 4s ago
 Main PID: 5939 (mongod)
   Memory: 48.6M
   CGroup: /system.slice/mongod.service
           └─5939 /usr/bin/mongod --config /etc/mongod.conf

Aug 22 23:40:54 debian1 systemd[1]: Started MongoDB Database Server.
Aug 22 23:40:54 debian1 mongod[5939]: 2019-08-22T23:40:54.447+0200 I STORAGE  [main] Max cache overflow file size custom option: 0

The service listens on localhost TCP port 27017 by default.

$ sudo ss -tunelp
Netid   State    Recv-Q   Send-Q     Local Address:Port        Peer Address:Port                                                                   
udp     UNCONN   0        0           *       users:(("dhclient",pid=440,fd=7)) ino:13373 sk:1 <->           
tcp     LISTEN   0        128    *       users:(("mongod",pid=5939,fd=11)) uid:106 ino:35394 sk:2 <->   
tcp     LISTEN   0        128         *       users:(("sshd",pid=602,fd=3)) ino:14676 sk:3 <->               
tcp     LISTEN   0        128                 [::]:22                  [::]:*       users:(("sshd",pid=602,fd=4)) ino:14678 sk:4 v6only:1 <->

This setting can be altered on the /etc/mongod.conf file.

# network interfaces
  port: 27017

The IP can be replaced with an IP address on the server’s network interface to bind to.

Restart mongod service if a change is made.

sudo systemctl restart mongod

To get to MongoDB shell, run:

$ mongo
MongoDB shell version 4.4.8
connecting to: mongodb://
Implicit session: session  "id" : UUID("9a688b2e-251c-4951-b92b-28218c9a4154") 
MongoDB server version: 4.4.8
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
Questions? Try the support group
Server has startup warnings: 
2019-10-25T21:07:38.418+0000 I  STORAGE  [initandlisten] 
2019-10-25T21:07:38.418+0000 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-10-25T21:07:38.418+0000 I  STORAGE  [initandlisten] **          See
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-10-25T21:07:38.907+0000 I  CONTROL  [initandlisten] 
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()


More reading:  How to configure MongoDB 4 authentication.


Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.