How to Setup MongoDB server in Amazon Linux 2

You are currently viewing How to Setup MongoDB server in Amazon Linux 2

In this article, I will show you how to install MongoDB on Amazon Linux 2, which is one the most popular NoSQL database provider in this planet earth.

What is actually Mongodb

According to Wikipedia, MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License. 

How to Install mongoDB on Amazon Linux 2

At first create a new instance using Amazon Linux 2 AMI. I have an article on creating new ec2 instance here.

Then update the YUM packages by running this command.

sudo yum update -y

Next, create a /etc/yum.repos.d/mongodb-org-4.4.repo file so that you can install MongoDB directly using yum.

[mongodb-org-4.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2/mongodb-org/4.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc

To install the latest stable version of MongoDB, issue the following command:

sudo yum install -y mongodb-org

That’s it. You have successfully installed MongoDB into your EC2 instance.

Now you can start the mongod process by issuing the following command.

sudo systemctl start mongod

This will make the MongoDB started. Next, you can optionally ensure that MongoDB will start following a system reboot by issuing the following command.

sudo systemctl enable mongod

Now as you have started MongoDB, now run this command to start a mongo shell.

mongo

If you stuck at any point of this example, then feel free to watch my screen recording here.

Conclusion

Companies and development teams of all sizes use MongoDB because The document data model is a powerful way to store and retrieve data that allows developers to move fast. MongoDB’s horizontal, scale-out architecture can support huge volumes of both data and traffic. The motivation of the MongoDB language is to implement a data store that provides high performance, high availability, and automatic scaling. MongoDB is extremely simple to install and implement. MongoDB uses JSON or BSON documents to store data. I hope my tutorial will help you to get started with MongoDB. If you get stuck in any situation then please watch my youtube video and follow the instructions given there.

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply