
MongoDB is an open-source NoSQL document database that stores data in a JSON-like format. To install MongoDB on Rocky Linux 9, you can take advantage of its flexible data model, which allows you to store unstructured data and create documents with different schema while providing full indexing support. It also supports ad-hoc queries, indexing, and database replication for high availability using replica sets.
This guide explains how to install MongoDB on a Rocky Linux 9 server. You will secure the database server and create sample documents to verify the installation.
Before you begin, you need to:
MongoDB is not available in the default Rocky Linux 9 repositories. Follow the steps below to add the MongoDB repository to your DNF package manager sources and install MongoDB on your server.
Visit the MongoDB releases page and verify the latest version to install on your server. For example, MongoDB 8.0.
Create a new mongodb-org-8.0.repo MongoDB repository configuration file.
Add the following configurations to the file.
Save and close the file.
Update the server's package index to apply the repository changes.
Install MongoDB.
Swap the default mongodb-mongosh shell package with the mongodb-mongosh-shared-openssl3 package.
OpenSSL 3 is the default OpenSSL version on Rocky Linux 9, and the default mongodb-mongosh MongoDB shell package is not compatible with the version. Installing the mongodb-mongosh-shared-openssl3 package enables MongoDB to use OpenSSL 3 on your server.
MongoDB uses the mongod system service to manage the database server runtime and processes. Follow the steps below to enable the MongoDB service to start at boot and run it on your server.
Enable MongoDB to start automatically at system boot.
Start the MongoDB service.
View the MongoDB service status and verify that it's running.
Output:
MongoDB uses plain authentication by default and does not require password usage to perform administrative tasks on the server. Follow the steps below to enable secure password authentication to access the MongoDB shell.
Access the MongoDB shell.
Switch to the admin database.
Create a new mongodbadmin administrative user with full privileges to any database. Then, enter a strong password when prompted.
Output:
View all MongoDB users and verify that the mongodbadmin user is available.
Output:
Exit the MongoDB shell.
Open the main mongod.conf MongoDB configuration file.
Add the following security configuration at the end of the file.
Save and close the file.
Restart the MongoDB service to apply the changes.
Follow the steps below to access the MongoDB shell to create new users, databases, and insert documents to a database.
Access the MongoDB shell using the mongodbadmin administrative user you created.
Enter the administrator password you created earlier when prompted.
Create a new vultr_test database.
Create a new user such as testuser with full privileges to the vultr_test database.
Enter a new strong user password when prompted.
Output:
Exit the MongoDB shell.
Access the MongoDB shell as testuser and enter the user password when prompted.
Switch to the vultr_test database.
Insert a new document into the database with the message Greetings from Vultr to create a new messages collection.
Output:
View all records in the messages collection and verify that the new document is available.
Output:
Exit the MongoDB shell.
You have installed MongoDB on Rocky Linux 9 and created a new database to verify the installation. You can use MongoDB to create databases, manage users, and store documents to match your application needs. For more information and configuration options, visit the MongoDB documentation.
0 Comments
Be the first to comment and share your perspective with the community.