<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">
Go to top icon

MongoDB Installation on Amazon Linux

Amit Tidke Feb 02, 2017

Amazon Linux MongoDB

MongoDB is an open source NoSQL database that uses a document-oriented data model. MongoDB is built on architecture of collection and document, whereas MySQL uses tables and rows. MongoDB uses JSON-like documents with schemas.

Key features of MongoDB:

  • High performance
  • Rich query language
  • High availability
  • Horizontal scalability
  • Support for multiple storage engines

How to install MongoDB?

If we want install MongoDB directly using yum then we have to add MongoDB repository. It is recommended to follow the installation steps as a root user.

Create a /etc/yum.repos.d/mongodb-org-3.4.repo

vim /etc/yum.repos.d/mongodb-org-3.4.repo

Add the following lines in the repository file [mongodb-org-3.4]

[mongodb-org-3.4]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/

gpgcheck=1

enabled=1

gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

Use the following command to install MongoDB

yum install -y mongodb-org

Start MongoDB

We can start mongoDB service by using following command:

servicemongod start

Verify if MongoDB has started

You can verify if MongoDB process has started or not by checking the content of MongoDB log file which is located at /var/log/mongodb/mongod.log

You should see following line in log file:
[initandlisten] waiting for connections on port 27017

Where 27017 is default port. You can configure another port in configuration file located at /etc/mongod.conf

If you want to start the MongoDB after every system reboot, you can use following command to do the same

chkconfigmongod on

Stop MongoDB

You can use following command to stop MongoDB

servicemongod stop

Restart MongoDB

You can use following command to restart MongoDB

servicemongod restart

By Default MongoDB stores its data file in /var/lib/mongo and its log file in

/var/log/mongoDB.

We can specify alternate path for data and log directory by modifying /etc/mongod.conf

Uninstall MongoDB

To remove MongoDB completely from the system, we have remove MongoDB application, related configuration files, logs files and any other directories containing data files.

Follow the below steps to remove the MongoDB

  • Stop MongoDB

Stop MongoDB by using following command

servicemongod stop

  • Remove Packages

Remove any MongoDB packages that we had previously installed

sudo yum erase $(rpm -qa | grepmongodb-org)

  • Remove Data Directories

Remove all data and log files

sudorm -r /var/log/mongodb

sudorm -r /var/lib/mongo

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.