How to install MongoDB in CentOS 7

by Daniel Pham
Published: Updated:

How to install MongoDB in CentOS 7? This article will guide you step by step how to install it successfully.

MongoDB is a well-known database type, many large systems are using it, especially the development of IoT.

Add MongoDB repository to the server

First, just like database types like MariaDB, MongoDB allows you to install it through the repository.

Type the command below to create MongoDB repository file.\

yum install nano -y && nano /etc/yum.repos.d/mongodb-org-4.0.repo

Then, copy the text below into the file above and save it.

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

Install MongoDB in CentOS 7

You type the following command to proceed with MongoDB installation for CentOS 7 server.

In the demo, I am using CentOS version 7.6.1810 (Core) and the current MongoDB version is 4.0.9.

yum install -y mongodb-org

You can see more information about installation at the MongoDB tutorial page.

After installation is complete, type the following command to start the service.

service mongod start

Type below command to enable MongoDB’s service auto start after reboot.

chkconfig mongod on

And then, you check to see if the service is working.

service mongod status

The result like this.

[root@db01 ~]# service mongod status
Redirecting to /bin/systemctl status mongod.service
 mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-04-16 21:23:49 +07; 18h ago
     Docs: https://docs.mongodb.org/manual
  Process: 27437 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
  Process: 27435 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 27433 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 27431 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 27441 (mongod)
   CGroup: /system.slice/mongod.service
           └─27441 /usr/bin/mongod -f /etc/mongod.conf

Apr 16 21:23:48 db01 systemd[1]: Starting MongoDB Database Server...
Apr 16 21:23:48 db01 mongod[27437]: about to fork child process, waiting until server is ready for connections.
Apr 16 21:23:48 db01 mongod[27437]: forked process: 27441
Apr 16 21:23:49 db01 systemd[1]: Started MongoDB Database Server.

Like other databases, it also has shell cli for you to work with the database.

Type mongo to enter shell cli.

use mongo command to login MongoDB shell cli
Use ‘mongo’ command to login MongoDB shell cli.

Conclusion

Installing MongoDB in CentOS 7 is really simple. In fact, it only takes about 2-3 lines of code to complete the installation. Yes, installation is one thing and using it is another.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.

SUPPORT US

FOLLOW US

Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 DevOpsLite.com – All rights reserved.

Please write sources “DevOpsLite.com” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

0
Would love your thoughts, please comment.x
()
x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.