How To Install MongoDB Community Edition on Linux CentOS 7
On this short article, we will learn how to install MongoDB version 4.2.2 Community Edition on CentOS 7 operating system.
Introduction
MongoDB is classified as a NoSQL database which is different than traditional table-based SQL databases like Oracle, MariaDB, MySQL and PostgreSQL. MongoDB is a free and open-source document database. Data is stored as JSON-like documents where fields can vary from document to document. It does not require a predefined schema and data structure can be changed over time. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL). In this article, we will discuss how to install and configure MongoDB Community Edition on CentOS 7, the source is using official MongoDB repositories.
MongoDB Installation on CentOS 7
There are any MongoDB Community Edition distribution for any platform, For Linux, OS X, and Windows. For Linux distribution itself, it has been provided MongoDB for various Linux systems, namey : Red Hat, SUSE, Amazon, Ubuntu and Debian.
There are several steps to be followed to install MongoDB on CentOS 7 environment.
- Prerequisites
- Enabling MongoDB repository
- Installing MongoDB
- Starting MongoDB
- Verifying MongoDB Installation
We will use MongoDB repositories is version 4.2.
Prerequisites
Before installing MongoDB in CentOS7, we have to prepare the environment first. It requires a user with sudo privileges, sufficient space and the last update of CentOS repository. In our environment we have all the necessary requirements.
Enabling MongoDB repository
The first step in installing MongoDB is to add MongoDB repository to the system. By using vi text editor we will create a new repo file for MongoDB.
$ cd /etc/yum.repos.d/ $ sudo vi /etc/yum.repos.d/mongodb-org-4.2.repo
Add the copying the following text to the file.
[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
Install MongoDB on CentOS 7
After adding MongoDB repository, then we will install MongoDB server by submitting command line :
$ sudo yum -y update $ sudo yum install -y mongodb-org
The output :
[ramans@localhost yum.repos.d]$ sudo yum install -y mongodb-org Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.mirror.angkasa.id * extras: centos.mirror.angkasa.id * updates: centos.mirror.angkasa.id base | 3.6 kB 00:00:00 docker-ce-stable | 3.5 kB 00:00:00 extras | 2.9 kB 00:00:00 mongodb-org-4.2 | 2.4 kB 00:00:00 updates | 2.9 kB 00:00:00 mongodb-org-4.2/7/primary_db | 18 kB 00:00:02 Resolving Dependencies --> Running transaction check ---> Package mongodb-org.x86_64 0:4.2.2-1.el7 will be installed --> Processing Dependency: mongodb-org-tools = 4.2.2 for package: mongodb-org-4.2.2-1.el7.x86_64 --> Processing Dependency: mongodb-org-shell = 4.2.2 for package: mongodb-org-4.2.2-1.el7.x86_64 --> Processing Dependency: mongodb-org-server = 4.2.2 for package: mongodb-org-4.2.2-1.el7.x86_64 --> Processing Dependency: mongodb-org-mongos = 4.2.2 for package: mongodb-org-4.2.2-1.el7.x86_64 --> Running transaction check ---> Package mongodb-org-mongos.x86_64 0:4.2.2-1.el7 will be installed ---> Package mongodb-org-server.x86_64 0:4.2.2-1.el7 will be installed ---> Package mongodb-org-shell.x86_64 0:4.2.2-1.el7 will be installed ---> Package mongodb-org-tools.x86_64 0:4.2.2-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================== Package Arch Version Repository Size ====================================================================================================== Installing: mongodb-org x86_64 4.2.2-1.el7 mongodb-org-4.2 5.8 k Installing for dependencies: mongodb-org-mongos x86_64 4.2.2-1.el7 mongodb-org-4.2 14 M mongodb-org-server x86_64 4.2.2-1.el7 mongodb-org-4.2 25 M mongodb-org-shell x86_64 4.2.2-1.el7 mongodb-org-4.2 17 M mongodb-org-tools x86_64 4.2.2-1.el7 mongodb-org-4.2 47 M Transaction Summary ====================================================================================================== Install 1 Package (+4 Dependent packages) Total download size: 103 M Installed size: 260 M Downloading packages: warning: /var/cache/yum/x86_64/7/mongodb-org-4.2/packages/mongodb-org-4.2.2-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID 058f8b6b: NOKEY Public key for mongodb-org-4.2.2-1.el7.x86_64.rpm is not installed (1/5): mongodb-org-4.2.2-1.el7.x86_64.rpm | 5.8 kB 00:00:01 (2/5): mongodb-org-mongos-4.2.2-1.el7.x86_64.rpm | 14 MB 00:00:09 (3/5): mongodb-org-shell-4.2.2-1.el7.x86_64.rpm | 17 MB 00:00:08 (4/5): mongodb-org-server-4.2.2-1.el7.x86_64.rpm | 25 MB 00:00:24 (5/5): mongodb-org-tools-4.2.2-1.el7.x86_64.rpm | 47 MB 00:00:16 ------------------------------------------------------------------------------------------------------ Total 2.9 MB/s | 103 MB 00:00:35 Retrieving key from https://www.mongodb.org/static/pgp/server-4.2.asc Importing GPG key 0x058F8B6B: Userid : "MongoDB 4.2 Release Signing Key <packaging@mongodb.com>" Fingerprint: e162 f504 a20c df15 827f 718d 4b7c 549a 058f 8b6b From : https://www.mongodb.org/static/pgp/server-4.2.asc Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mongodb-org-shell-4.2.2-1.el7.x86_64 1/5 Installing : mongodb-org-mongos-4.2.2-1.el7.x86_64 2/5 Installing : mongodb-org-tools-4.2.2-1.el7.x86_64 3/5 Installing : mongodb-org-server-4.2.2-1.el7.x86_64 4/5 Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service. Installing : mongodb-org-4.2.2-1.el7.x86_64 5/5 Verifying : mongodb-org-4.2.2-1.el7.x86_64 1/5 Verifying : mongodb-org-server-4.2.2-1.el7.x86_64 2/5 Verifying : mongodb-org-tools-4.2.2-1.el7.x86_64 3/5 Verifying : mongodb-org-mongos-4.2.2-1.el7.x86_64 4/5 Verifying : mongodb-org-shell-4.2.2-1.el7.x86_64 5/5 Installed: mongodb-org.x86_64 0:4.2.2-1.el7 Dependency Installed: mongodb-org-mongos.x86_64 0:4.2.2-1.el7 mongodb-org-server.x86_64 0:4.2.2-1.el7 mongodb-org-shell.x86_64 0:4.2.2-1.el7 mongodb-org-tools.x86_64 0:4.2.2-1.el7 Complete!
Start MongoDB Service
MongoDB service must be enabled and started to run properly. For this purpose we will enable MongoDB service, by submitting command line below :
$ sudo systemctl start mongod $ sudo systemctl enable mongod
Then we will try to connect to the MongoDB version by submitting command line :
$ mongo
The output :
[ramans@localhost yum.repos.d]$ mongo MongoDB shell version v4.2.2 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("4d14fef1-f478-4464-be87-fe3eb049dda7") } MongoDB server version: 4.2.2 Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2020-01-02T20:50:43.986+0700 I CONTROL [initandlisten] 2020-01-02T20:50:43.986+0700 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2020-01-02T20:50:43.986+0700 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2020-01-02T20:50:43.986+0700 I CONTROL [initandlisten] 2020-01-02T20:50:43.987+0700 I CONTROL [initandlisten] 2020-01-02T20:50:43.987+0700 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2020-01-02T20:50:43.987+0700 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2020-01-02T20:50:43.987+0700 I CONTROL [initandlisten] 2020-01-02T20:50:43.987+0700 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2020-01-02T20:50:43.987+0700 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2020-01-02T20:50:43.987+0700 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() --- >
Inside database prompt, we also could verify our MongoDB version by submitting command line.
> db.version() 4.2.2
Conclusion
On this short article, we have shown you how to install MongoDB Community Edition on CentOS 7 successfully.