MongoDB is a widely used open-source NoSQL database management system. It is highly scalable and provides high performance for large data sets. In this guide, we will walk you through the step-by-step process of installing MongoDB on a CentOS 7 server.
Pre-requisites:
There are certain prerequisites that need to be met before you begin:
- Server running CentOS 6 / CentOS 7 / CentOS 8
- Access to SSH connected text editor
- User account with root or sudo access
- Internet connection
Step 1: Enter as Root User
For making changes in the configuration file, you need to enter as a root user, with the following command:
sudo -i
Step 2: Setting up Environment for MongoDB
- The MongoDB repository is not included in the default CentOS 7 package repositories. Therefore, you need to add it manually. Create a MongoDB repository file under the /etc/yum.repos.d/ directory using the following command:
nano /etc/yum.repos.d/mongodb-org-4.4.repo
Note: If you get the error nano: command not found, enter as root user and then install the nano text editor, using the following command:
sudo -i
yum install nano
When asked Is this Ok, enter y to continue the installation.
- Add the following lines in the mongodb-org-4.4.repo configuration file:
[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
Once, you have added the lines in the configuration file, save and close it using the commands Ctrl + O, press enter and then enter Ctrl +X.
- Now that the MongoDB repository is added, use the following command to install the latest stable version of MongoDB:
sudo yum install -y mongodb-org
Executing this command will install the MongoDB package as well as all the necessary dependencies required for its proper functioning.
By now, you should have successfully installed MongoDB on your system.
Step 4: Start MongoDB Service
After the installation is complete, start the MongoDB service using the following command:
systemctl start mongod.service
To ensure that MongoDB starts automatically at system boot, run the following command:
sudo systemctl enable mongod.service
Step 5: Verify MongoDB Installation
To verify the installation, use the following command to check the MongoDB service status:
sudo systemctl status mongodb
Step 6: Connect to MongoDB
You can connect to the MongoDB server using the mongo shell command:
mongo
This will open the MongoDB shell. You can now start using MongoDB.
Conclusion: You have successfully installed MongoDB on your CentOS 7 server. You can now start using MongoDB to manage your data.