Welcome to our guide which covers the installation of MongoDB 4.4 on Amazon Linux 2. MongoDB is well adopted, free to use, open source and cross-platform NoSQL document-oriented database system developed by MongoDB Inc. It uses JSON-like documents with optional schemas. MongoDB offers both a Community and an Enterprise version of the database:
- MongoDB Community: The source available and free to use edition of MongoDB.
- MongoDB Enterprise: This is available as part of the MongoDB Enterprise Advanced subscription and includes comprehensive support for your MongoDB deployment. It enterprise-focused features such as LDAP and Kerberos support, on-disk encryption, and auditing.
In this article we will be installing MongoDB Community edition on Amazon Linux 2. Some of the key features of MongoDB are:
- High Performance: MongoDB provides support for embedded data models which reduces I/O activity on database system. It also indexes support faster queries and can include keys from embedded documents and arrays.
- High Availability: MongoDB has a replication facility called replica set which provides automatic failover and data redundancy.
- Rich Query Language: MongoDB supports a rich query language to support read and write operations (CRUD) as well as Data Aggregation and Text Search and Geospatial Queries.
- Horizontal Scalability: MongoDB provides horizontal scalability as part of its core functionality
- Support for Multiple Storage Engines: MongoDB supports multiple storage engines
How To Install MongoDB 4.4 on Amazon Linux 2
You’ll have to follow steps in the next sections to install MongoDB 4.4 Community Edition on Amazon Linux using the yum package manager.
Step 1: Update Amazon Linux Server
Use the following command to verify which Linux distribution you are running:
$ grep ^NAME /etc/*release
/etc/os-release:NAME="Amazon Linux"
Update your system to have the latest packages installed.
sudo yum -y update
Consider a reboot after system update.
sudo systemctl reboot
Step 2: Add MongoDB repository to Amazon Linux 2
After upgrading the packages on the server and rebooting proceed to add MongoDB 4.4 Community repository which holds RPM packages for Amazon Linux.
sudo tee /etc/yum.repos.d/mongo.repo<<EOF
[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
EOF
You can cat the contents of the file created to confirm it is correct.
$ cat /etc/yum.repos.d/mongo.repo
Step 3: Install MongoDB 4.4 packages on Amazon Linux 2
Finally use yum package manager tool to install MongoDB 4.4 packages on Amazon Linux 2.
sudo yum -y install mongodb-org
By default, MongoDB instance stores:
- its data files in
/var/lib/mongo
- its log files in
/var/log/mongodb
Use the following command to start mongod process on Amazon Linux 2:
sudo systemctl start mongod
Ensure the service is set to start at system boot.
sudo systemctl enable mongod
Verify that the mongod process has started successfully:
$ systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-08-18 17:51:53 UTC; 53s ago
Docs: https://docs.mongodb.org/manual
Main PID: 5363 (mongod)
CGroup: /system.slice/mongod.service
└─5363 /usr/bin/mongod -f /etc/mongod.conf
Aug 18 17:51:52 amazon-linux systemd[1]: Starting MongoDB Database Server...
Aug 18 17:51:52 amazon-linux mongod[5359]: about to fork child process, waiting until server is ready for connections.
Aug 18 17:51:52 amazon-linux mongod[5359]: forked process: 5363
Aug 18 17:51:53 amazon-linux systemd[1]: Started MongoDB Database Server.
Start a mongo shell on the same host machine as the mongod:
$ mongo
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("4a6983fa-a9f8-4db6-9db4-18382693ed61") }
MongoDB server version: 4.4.0
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
https://docs.mongodb.com/
Questions? Try the MongoDB Developer Community Forums
https://community.mongodb.com
---
The server generated these startup warnings when booting:
2020-08-18T17:51:52.556+00:00: ***** SERVER RESTARTED *****
2020-08-18T17:51:53.065+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
>
Learn more on MongoDB from the official project documentation page.