Installing MongoDB on CentOS
Installing MongoDB on CentOS: A Step-by-Step Guide
MongoDB is a popular NoSQL database known for its flexibility, scalability, and ease of use. In this guide, we will walk you through the process of installing MongoDB on a CentOS operating system.
Prerequisites
Before we begin, ensure that you have the following:
- A CentOS server with root or sudo privileges
- An internet connection
Step 1: Update the System
First, update your system packages to the latest versions.
sudo yum update -y
Step 2: Add MongoDB Repository
To install MongoDB, we need to add its repository to the system.
- Create a
/etc/yum.repos.d/mongodb-org-6.0.repo
file using a text editor likenano
orvi
.
Step 3: Install MongoDB
Install MongoDB packages using the following command:
sudo yum install -y mongodb-org
This command installs the following packages:
mongodb-org-server
: The mongod daemon and associated configuration filesmongodb-org-mongos
: The mongos daemonmongodb-org-shell
: The mongo shellmongodb-org-tools
: MongoDB tools (e.g.,mongodump
,mongorestore
)
Step 4: Start and Enable MongoDB
Start the MongoDB service and enable it to start on boot
sudo systemctl start mongod
sudo systemctl enable mongod
Step 5: Verify MongoDB Installation
Verify that MongoDB is running by checking its status.
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
(127.0.0.1). If you want MongoDB to be accessible from a different IP address, you need to modify the MongoDB configuration file.
- Open the MongoDB configuration file.
net
section and update the bindIp
value to your desired IP address.Replace 192.168.1.100
with your server's IP address.
Save and close the file.
Restart MongoDB to apply the changes.
Step 7: Secure MongoDB
It's important to secure your MongoDB installation, especially if it's exposed to the internet.
- Create an administrative user.
Replace yourpassword
with a strong password.
- Enable authentication by editing the MongoDB configuration file.
security
section.Save and close the file.
Restart MongoDB to apply the changes.
sudo systemctl restart mongod
Step 8: Connect to MongoDB
Connect to MongoDB using the mongo shell and the administrative user you created.
mongo -u admin -p --authenticationDatabase admin
Enter your password when prompted.
Conclusion
Congratulations! You have successfully installed MongoDB on CentOS. You can now start using MongoDB to build powerful and scalable applications. Remember to regularly update your MongoDB installation and secure it against unauthorized access.
Comments
Post a Comment