In this tutorial, we’ll walk through the process of installing MongoDB on Amazon Linux 2023 without using Docker. MongoDB is a popular NoSQL database used for building modern applications, and Amazon Linux is a stable, secure, and high-performance environment. Installing MongoDB directly on the OS (as opposed to using Docker) can offer performance advantages and fewer layers to manage.
Let’s dive in!
Prerequisites
- An Amazon EC2 instance is running Amazon Linux 2023.
- Root or sudo access to the instance.
Step-by-step Installation Guide
Connect to Your Instance
Using SSH, connect to your Amazon EC2 instance.
ssh ec2-user@your-instance-ip-address
Update the System
Before installing any new software, it’s always a good idea to update the existing packages:
sudo dnf update -y
Configure the MongoDB Repository
To install MongoDB, you’ll first need to create a .repo
file under /etc/yum.repos.d/
:
[mongodb-org-8.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2023/mongodb-org/8.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://pgp.mongodb.com/server-8.0.asc
Note: This example uses the MongoDB 8.0 repository. For the latest version, you may want to check MongoDB’s official site.
Install MongoDB
Install the Mongosh with OpenSSL first
sudo dnf remove -y mongodb-mongosh
sudo dnf install -y mongodb-mongosh-shared-openssl3
sudo dnf install -y mongodb-mongosh
Now that you’ve set up the repository, you can install MongoDB:
sudo dnf install -y mongodb-org
This command will install several packages, including:
mongodb-org-server: The MongoDB server itself.
mongodb-org-mongos: The MongoDB Shard service.
mongodb-org-shell: The MongoDB shell, is useful for administrative tasks.
mongodb-org-tools: Essential MongoDB tools.
Start MongoDB
With MongoDB installed, you can now start the service:
sudo systemctl start mongod
If you want MongoDB to start automatically at boot:
sudo systemctl enable mongod
Verify the Installation
Check the MongoDB service status:
sudo systemctl status mongod
You can also connect to your MongoDB server using the MongoDB shell:
mongosh
The MongoDB shell prompt should greet you.
Connect with MongoDB Compass
Edit the “/etc/mongod.conf” file and allow
sudo nano /etc/mongod.conf
Add the following minimal configuration to allow remote connections
net:
port: 27017
bindIp: 0.0.0.0
Once you update the configure file, you must allow inbound traffic to your EC2 instance on the MongoDB port (default: 27017) from your local machine.
After that, you can connect using MongoDB Compass by creating a connection using the following connection string
mongodb://<EC2_Public_IP>:27017
Here is the video tutorial available for you to view
Conclusion
Congratulations! You’ve successfully installed MongoDB on Amazon Linux 2023 without using Docker. You can now proceed to configure and use your MongoDB instance for application development, testing, or production purposes. Remember to consult the official MongoDB documentation for best practices, especially regarding security and optimization.
its to good but we also want how we can connect mongoDB compass to it
Edit the /etc/mongod.conf file and allow
sudo nano /etc/mongod.conf
Add the following minimal configuration to allow remote connections
net:
port: 27017
bindIp: 0.0.0.0