MongoDB is a leading NoSQL database commonly used in modern web applications. This tutorial will walk you through setting up MongoDB on Red Hat Enterprise Linux (RHEL) and CentOS Linux:
Update your system before beginning installation.
Install MongoDB with the yum package manager.
Create the /etc/yum.repos.d/mongodb-org-4.4.repo file for MongoDB.
# nano /etc/yum.repos.d/mongodb-org-4.4.repo
Paste the following into the editor:
[mongodb-org-4.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
Save and exit the file.
To install the latest stable version of MongoDB:
# sudo yum install -y mongodb-org
If you need to install a specific version or prevent automatic upgrades, see the MongoDB documentation.
# systemctl start mongod.service # systemctl enable mongod.service
Connect to MongoDB.
MongoDB is not secure by default. Use our guide to configure MongoDB security and authentication.
Note: Any start-up warnings related to
Readahead can be safely ignored. To prevent these warnings, verify that the sectors are "as stated" in the warning by running
blockdev –getra /dev/vda1. If the output is greater than 512, run the following commands:
blockdev --setra 512 /dev/vda1 systemctl restart mongod
The warning will now be resolved.