How to Install MongoDB on AlmaLinux 8
MongoDB is a NoSQL database that provides high performance, high availability, and easy scalability. In this guide, we will walk you through the steps to install MongoDB on AlmaLinux 8.
Step 1: Update Your System
Start by ensuring your system is up to date:sudo dnf update -y
Step 2: Add the MongoDB Repository
Create a file for the MongoDB repository:echo "[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/8/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc" | sudo tee /etc/yum.repos.d/mongodb-org-5.0.repo
Step 3: Install MongoDB
Now, install MongoDB using the following command:sudo dnf install -y mongodb-org
Step 4: Start and Enable MongoDB
Start the MongoDB service and enable it to start at boot:sudo systemctl start mongod
sudo systemctl enable mongod
Step 5: Verify the Installation
Check the status of the MongoDB service to ensure it is running:sudo systemctl status mongod
Step 6: Secure MongoDB
By default, MongoDB is not secured. To secure it, first enable authentication. Edit the MongoDB configuration file:sudo nano /etc/mongod.conf
Add the following lines to the configuration file:
security:
authorization: "enabled"
Save and exit the editor, then restart MongoDB:
sudo systemctl restart mongod
Step 7: Create an Admin User
Connect to the MongoDB shell:mongo
Run the following commands to create an admin user:
use admin
db.createUser({user: "admin", pwd: "your_password", roles: [{role: "userAdminAnyDatabase", db: "admin"}]})
Replace your_password
with a strong password.
Comments
Post a Comment