How to Install MongoDb on CentOS 8

It’s all about database. I love database, no matter if its MSSQL Server, MySQL, PostgreSQL or even Oracle. But today, I want to improve my knowledge on MongoDb. It is a popular NoSQL database available out there but I don’t have much chance to try it on my own system. I hope this MongoDb supports spatial dataset so I can store my GIS layers, shapefile into the MongoDb. So in this article, I will show you how I install MongoDb on CentOS 8.

Steps to Install MongoDb on CentOS 8

Step 1. Create MongoDb Repo file

First, we need to create a repo file. With this file, we can then install MongoDb via Yum command.

su
nano /etc/yum.repos.d/mongodb-org-4.2.repo

And then paste these lines

 [mongodb-org-4.2]
 name=MongoDB Repository
 baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
 gpgcheck=1
 enabled=1
 gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

Step 2. Install MongoDb

Once we set up the repository, we can now install MongoDb on CentOS 8 with this command

yum install mongodb-org

Output

Wait until the installation process completes. For more information, please visit the official MongoDb documentation below.

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

Step 3. Start MongoDb Service

Now, let’s start the MongoDb service and enable it upon system boot with this command

systemctl start mongod.service
systemctl enable mongod.service

Now check the service status

systemctl status mongod.service

You should see something like this

[root@centos yum.repos.d]# systemctl status mongod
 ● mongod.service - MongoDB Database Server
    Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
    Active: active (running) since Fri 2020-01-24 09:25:14 EST; 13s ago
      Docs: https://docs.mongodb.org/manual
  Main PID: 19388 (mongod)
    Memory: 72.3M
    CGroup: /system.slice/mongod.service
            └─19388 /usr/bin/mongod -f /etc/mongod.conf
 Jan 24 09:25:13 centos.griyaku.lan systemd[1]: Starting MongoDB Database Server…
 Jan 24 09:25:13 centos.griyaku.lan mongod[19363]: about to fork child process, waiting until server is ready for connections.
 Jan 24 09:25:13 centos.griyaku.lan mongod[19363]: forked process: 19388
 Jan 24 09:25:14 centos.griyaku.lan mongod[19363]: child process started successfully, parent exiting
 Jan 24 09:25:14 centos.griyaku.lan systemd[1]: Started MongoDB Database Server.

At this point, we have successfully install MongoDb on CentOS 8. You may need to set the firewalld from enforcing to permissive. You can read how to do this here.

How to Connect to MongoDb Server

So now I have a fully functioning MongoDb server. But how can I connect to it and do some basic query or standard database listing? To connect to the MongoDb server, simply type “mongo” in Terminal.

mongo

Output:

To exit from the MongoDb console, type “exit;”. See the following video showing how to connect and exit from MongoDb console.

Connect to MongoDb console

Thanks for reading this article.

Be the first to comment

Leave a Reply