MongoDB is a powerful and flexible open-source NoSQL database, widely used for big data and web applications. In this tutorial, we’ll walk you through the step-by-step process of how to install MongoDB on Scientific Linux.
Note: This guide assumes that you have root access to your Scientific Linux system.
Table of Contents
- Prerequisites
- Installing MongoDB
- Configuring MongoDB
- Starting and Enabling MongoDB
- Testing MongoDB
- Securing MongoDB
- Conclusion
How to Install MongoDB on Scientific Linux
Prerequisites
Before proceeding, ensure that your system is up to date by running the following commands:
sudo yum update
sudo yum upgrade
Next, you’ll need to install some necessary packages. If you haven’t already installed a text editor like nano or vim, follow our guides on how to install nano on Scientific Linux or how to install vim on Scientific Linux.
Installing MongoDB on Scientific Linux
Now, let’s install MongoDB on your Scientific Linux system. Follow these steps:
- First, create a new repository file for MongoDB:
sudo nano /etc/yum.repos.d/mongodb-org.repo
- Next, add the following repository information to the 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
- Save the file and exit the text editor.
- Now, you can install MongoDB by running:
sudo yum install -y mongodb-org
MongoDB is now installed on your system.
Configuring MongoDB on Scientific Linux
Before starting MongoDB, you should configure it according to your requirements. To do this, edit the MongoDB configuration file using your preferred text editor:
sudo nano /etc/mongod.conf
In this file, you can adjust settings such as bindIp
, port
, dbPath
, and more. For more information on configuring MongoDB, refer to the official MongoDB documentation.
After making the necessary changes, save the file and exit the text editor.
Starting and Enabling MongoDB on Scientific Linux
To start the MongoDB service, run the following command:
sudo systemctl start mongod
To ensure that MongoDB starts automatically upon system boot, enable the service:
sudo systemctl enable mongod
Testing MongoDB on Scientific Linux
Now, let’s verify that MongoDB is functioning correctly. First, check the status of the MongoDB service:
sudo systemctl status mongod
You should see an output indicating that the service is active and running.
Next, connect to the MongoDB shell by running:
mongo
You should now be connected to the MongoDB shell. Type exit
to quit the MongoDB shell.
Securing MongoDB on Scientific Linux
To secure your MongoDB installation, follow these steps:
- Connect to the MongoDB shell:
mongo
- Switch to the admin database:
use admin
Create a new user with the appropriate role and password:
db.createUser(
{
user: "your_username",
pwd: "your_password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
Replace your_username
and your_password
with the desired credentials.
Enable Authentication
To enable authentication, open the MongoDB configuration file:
sudo nano /etc/mongod.conf
Add the following lines under the security
section:
security:
authorization: enabled
Save and exit the file. Now restart the MongoDB service:
sudo systemctl restart mongod
MongoDB is now installed and configured with authentication enabled.
Connect to MongoDB
To connect to MongoDB with authentication, use the following command:
mongo -u your_username -p your_password --authenticationDatabase admin
Replace your_username
and your_password
with the appropriate credentials.
Conclusion
Congratulations! You have successfully installed and configured MongoDB on your Scientific Linux system. You now have a powerful, scalable, and document-oriented database to use for your applications. For further information and to learn more about MongoDB, visit the official MongoDB documentation.
For those interested in exploring other database management systems, we also have guides on how to install MariaDB on Scientific Linux, how to install PostgreSQL on Scientific Linux, and how to install MySQL on Scientific Linux. Additionally, you may find our articles on how to install Apache on Scientific Linux, how to install and configure Nginx on Scientific Linux and How to Configure Firewall on Scientific Linux helpful for setting up web servers.