Install MongoDB Enterprise on Amazon Linux
MongoDB Atlas and AWS
MongoDB Atlas is ahosted MongoDB service on AWS, for launching, running, andmaintaining MongoDB clusters.
Overview
Use this tutorial to install MongoDB Enterprise on Amazon LinuxAMI. MongoDB Enterprise is available on select platforms and containssupport for several features related to security and monitoring.
This installation guide only supports 64-bit systems. SeeSupported Platforms for more information.
Production Notes
Before deploying MongoDB in a production environment, consider theProduction Notes document.
Install MongoDB Enterprise
Note
To install a different version of MongoDB, please refer to thatversion’s documentation. To install the previous version, seethe tutorial for version 4.0.
Using .rpm Packages (Recommended)
- Amazon Linux 2
- Amazon Linux
Configure repository.
Create an /etc/yum.repos.d/mongodb-enterprise.repo
file so thatyou can install MongoDB enterprise directly using yum
:
- [mongodb-enterprise]
- name=MongoDB Enterprise Repository
- baseurl=https://repo.mongodb.com/yum/amazon/2/mongodb-enterprise/4.2/$basearch/
- gpgcheck=1
- enabled=1
- gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
You can also download the .rpm
files directly from theMongoDB repository. Downloads are organized by Amazon Linuxversion (e.g. 2
), then MongoDBrelease version(e.g. 4.2
), then architecture (e.g. x86_64
).Odd-numbered MongoDB release versions, such as 4.1, are developmentversions and are unsuitable for production deployment.
Install the MongoDB Enterprise packages.
Install MongoDB Enterprise 4.2.
Issue the following command:
- sudo yum install -y mongodb-enterprise
Install a specific release of MongoDB Enterprise.
To install a specific release, you must specify each component packageindividually along with the version number, as in thefollowing example:
- sudo yum install -y mongodb-enterprise-4.2.1 mongodb-enterprise-server-4.2.1 mongodb-enterprise-shell-4.2.1 mongodb-enterprise-mongos-4.2.1 mongodb-enterprise-tools-4.2.1
If you only install mongodb-enterprise=4.2.1
and do not include thecomponent packages, the latest version of each MongoDB package will beinstalled regardless of what version you specified.
Pin a specific version of MongoDB Enterprise.
Although you can specify any available version of MongoDBEnterprise, yum
upgrades the packages when a newerversion becomes available. To prevent unintended upgrades, pinthe package by adding the following exclude
directive to your/etc/yum.conf
file:
- exclude=mongodb-enterprise,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,mongodb-enterprise-tools
Configure repository.
Create an /etc/yum.repos.d/mongodb-enterprise.repo
file so thatyou can install MongoDB enterprise directly using yum
:
- [mongodb-enterprise]
- name=MongoDB Enterprise Repository
- baseurl=https://repo.mongodb.com/yum/amazon/2013.03/mongodb-enterprise/4.2/$basearch/
- gpgcheck=1
- enabled=1
- gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
You can also download the .rpm
files directly from theMongoDB repository. Downloads are organized by Amazon Linuxversion (e.g. 2013.03
), then MongoDBrelease version(e.g. 4.2
), then architecture (e.g. x86_64
).Odd-numbered MongoDB release versions, such as 4.1, are developmentversions and are unsuitable for production deployment.
Install the MongoDB Enterprise packages.
Install MongoDB Enterprise 4.2.
Issue the following command:
- sudo yum install -y mongodb-enterprise
Install a specific release of MongoDB Enterprise.
To install a specific release, you must specify each component packageindividually along with the version number, as in thefollowing example:
- sudo yum install -y mongodb-enterprise-4.2.1 mongodb-enterprise-server-4.2.1 mongodb-enterprise-shell-4.2.1 mongodb-enterprise-mongos-4.2.1 mongodb-enterprise-tools-4.2.1
If you only install mongodb-enterprise=4.2.1
and do not include thecomponent packages, the latest version of each MongoDB package will beinstalled regardless of what version you specified.
Pin a specific version of MongoDB Enterprise.
Although you can specify any available version of MongoDBEnterprise, yum
upgrades the packages when a newerversion becomes available. To prevent unintended upgrades, pinthe package by adding the following exclude
directive to your/etc/yum.conf
file:
- exclude=mongodb-enterprise,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,mongodb-enterprise-tools
Run MongoDB Enterprise
Production Notes
Before deploying MongoDB in a production environment, consider theProduction Notes document.
By default, MongoDB instance stores:
- its data files in
/var/lib/mongo
- its log files in
/var/log/mongodb
If you installed via the package manager, the directories are createdduring the installation.
If you installed manually by downloading the tarballs, you can createthe directories using mkdir -p <directory>
or sudo mkdir -p<directory>
depending on the user that will run MongoDB. (See yourlinux man pages for information on mkdir
and sudo
.)
By default, MongoDB runs using the mongod
user account. If youchange the user that runs the MongoDB process, you must also modifythe permission to the /var/lib/mongo
and /var/log/mongodb
directories to give this user access to these directories.
To specify a different log file directory and data file directory, editthe systemLog.path
and storage.dbPath
settings inthe /etc/mongod.conf
. Ensure that the user running MongoDB hasaccess to these directories.
Most Unix-like operating systems limit the system resources that asession may use. These limits may negatively impact MongoDB operation.See UNIX ulimit Settings for more information.
Start MongoDB.
You can start the mongod
process by issuing the followingcommand:
- sudo service mongod start
Verify that MongoDB has started successfully
You can verify that the mongod
process has startedsuccessfully by checking the contents of the log file at/var/log/mongodb/mongod.log
for a line reading
- [initandlisten] waiting for connections on port <port>
where <port>
is the port configured in /etc/mongod.conf
, 27017
by default.
You can optionally ensure that MongoDB will start following a systemreboot by issuing the following command:
- sudo chkconfig mongod on
Stop MongoDB.
As needed, you can stop the mongod
process by issuing thefollowing command:
- sudo service mongod stop
Restart MongoDB.
You can restart the mongod
process by issuing the followingcommand:
- sudo service mongod restart
You can follow the state of the process for errors or important messagesby watching the output in the /var/log/mongodb/mongod.log
file.
Begin using MongoDB.
Start a mongo
shell on the same host machine as themongod
. You can run the mongo
shellwithout any command-line options to connect to amongod
that is running on your localhost with defaultport 27017:
- mongo
For more information on connecting using the mongo
shell, such as to connect to a mongod
instance runningon a different host and/or port, see The mongo Shell.
To help you start using MongoDB, MongoDB provides GettingStarted Guides in various driver editions. SeeGetting Started for the available editions.
Uninstall MongoDB
To completely remove MongoDB from a system, you must remove the MongoDBapplications themselves, the configuration files, and any directories containingdata and logs. The following section guides you through the necessary steps.
Warning
This process will completely remove MongoDB, its configuration, and _all_databases. This process is not reversible, so ensure that all of yourconfiguration and data is backed up before proceeding.
Stop MongoDB.
Stop the mongod
process by issuing the following command:
- sudo service mongod stop
Remove Packages.
Remove any MongoDB packages that you had previously installed.
- sudo yum erase $(sudo rpm -qa | grep mongodb-enterprise)
Remove Data Directories.
Remove MongoDB databases and log files.
- sudo rm -r /var/log/mongodb
- sudo rm -r /var/lib/mongo
Additional Information
Security
Starting with MongoDB 3.6, MongoDB binaries, mongod
and mongos
, bind tolocalhost
by default.
When bound only to the localhost, these binaries can only acceptconnections from clients that are running on the same machine. Remoteclients cannot connect to the binaries bound only to localhost. Formore information, including how to override and bind to other ipaddresses, see Localhost Binding Compatibility Changes.
Packages
MongoDB provides officially supported Enterprise packages in their ownrepository. This repository contains the following packages:
Package Name | Description |
---|---|
mongodb-enterprise | A metapackage that will automatically installthe four component packages listed below. |
mongodb-enterprise-server | Contains the mongod daemon and associatedconfiguration and init scripts. |
mongodb-enterprise-mongos | Contains the mongos daemon. |
mongodb-enterprise-shell | Contains the mongo shell. |
mongodb-enterprise-tools | Contains the following MongoDB tools: mongoimport bsondump , mongodump , mongoexport ,mongofiles ,mongorestore , mongostat ,and mongotop . |