MongoDB, a popular NoSQL database, is known for its high performance, scalability, and flexibility. Whether you are working on small-scale projects or enterprise-level applications, installing MongoDB on your CentOS server can help you manage your data seamlessly. This guide walks you through the installation process step-by-step to get MongoDB up and running on CentOS.
Prerequisites
Before starting, make sure you have:
- A CentOS 7 or CentOS 8 system
- A user account with sudo or root privileges
- Access to the internet for downloading packages
Step 1: Update Your System
Ensure that your CentOS system is up-to-date before installing MongoDB. Run the following commands:
sudo yum update -y
sudo yum upgrade -y
Step 2: Add the MongoDB Repository
MongoDB is not included in the default CentOS repositories, so you need to add the official MongoDB repository manually.
- Create a
.repo
file in the/etc/yum.repos.d/
directory:
sudo vi /etc/yum.repos.d/mongodb-org-6.0.repo
- Add the following content to the file:
[mongodb-org-6.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/6.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-6.0.asc
Save and close the file.
Step 3: Install MongoDB
Now, install MongoDB by running the following command:
sudo yum install -y mongodb-org
This command installs the mongodb-org
package, which includes:
mongodb-org-server
– the main MongoDB servermongodb-org-mongos
– a routing service for sharded clustersmongodb-org-shell
– the interactive MongoDB shellmongodb-org-tools
– a collection of tools for database operations
Step 4: Start and Enable MongoDB
After the installation is complete, start the MongoDB service and enable it to start on boot:
sudo systemctl start mongod
sudo systemctl enable mongod
Step 5: Verify the Installation
To ensure MongoDB is running properly, check its status with:
sudo systemctl status mongod
You should see an output indicating that MongoDB is active and running.
Step 6: Configure MongoDB (Optional)
By default, MongoDB listens on localhost
. To allow remote connections, you need to modify the MongoDB configuration file:
- Open the configuration file:
sudo vi /etc/mongod.conf
- Find the
bindIp
line and change it as needed:
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
- Save and close the file, then restart MongoDB to apply changes:
sudo systemctl restart mongod
Step 7: Set Up Firewall Rules
If you need to access MongoDB from a remote location, you should open the necessary firewall port (default: 27017):
sudo firewall-cmd --zone=public --add-port=27017/tcp --permanent
sudo firewall-cmd --reload
Conclusion
Congratulations! You have successfully installed and configured MongoDB on your CentOS system. MongoDB is now ready to support your data-driven applications with its powerful and flexible database architecture.
Looking for professional support with database management or custom development solutions? Vibidsoft Pvt Ltd has a team of experts ready to assist with MongoDB installations, optimization, and more. Contact us today to ensure your infrastructure is set up for success!
Leave a Reply
You must be logged in to post a comment.