Install Using .tgz Tarball on Amazon Linux
Overview
The following tutorial downloads the .tgz
file directly to installMongoDB Enterprise on Amazon Linux. To install using yum
, seeInstall MongoDB Enterprise on Amazon Linux instead.
Prerequisites
MongoDB .tar.gz
tarballs require installing the followingdependencies:
- sudo yum install cyrus-sasl cyrus-sasl-plain cyrus-sasl-gssapi krb5-libs libcurl libpcap net-snmp openldap openssl
Procedure
Download the MongoDB Enterprise .tar.gz tarball.
After you have installed the required prerequisite packages, downloadthe MongoDB Enterprise tarball for your system from theMongoDB Download Center.
Extract the files from the downloaded archive.
For example, from a system shell, you can extract using the tar
command:
- tar -zxvf mongodb-linux-*-4.2.1.tgz
Ensure the binaries are in a directory listed in your PATH environment variable.
The MongoDB binaries are in the bin/
directory of the tarball.You can either:
- Copy the binaries into a directory listed in your
PATH
variable, such as/usr/local/bin
(Update/path/to/the/mongodb-directory/
with your installationdirectory as appropriate)
- sudo cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
- Create symbolic links to the binaries from a directory listed inyour
PATH
variable, such as/usr/local/bin
(Update/path/to/the/mongodb-directory/
with your installationdirectory as appropriate):
- sudo ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Run MongoDB
Create the data and log directories.
Note
Depending on user permissions, you may need to sudo mkdir -p<directory>
instead of mkdir -p <directory>
. Use or omitsudo
as appropriate. See your linux man pages for informationon mkdir
and sudo
.
Create a directory where the MongoDB instance stores its data. Forexample:
- sudo mkdir -p /var/lib/mongo
Create a directory where the MongoDB instance stores its log. For example:
- sudo mkdir -p /var/log/mongodb
The user that starts the MongoDB process must have read and writepermission to these directories. For example, if you intend to runMongoDB as yourself:
- sudo chown `whoami` /var/lib/mongo # Or substitute another user
- sudo chown `whoami` /var/log/mongodb # Or substitute another user
Run MongoDB.
To run MongoDB, run the mongod
process at the system prompt.
- mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
For details on the command-line options —dbpath
and —logpath
, seeOptions.
Verify that MongoDB has started successfully.
Verify that MongoDB has started successfully bychecking the process output for the following line in thelog file /var/log/mongodb/mongod.log
:
- [initandlisten] waiting for connections on port 27017
You may see non-critical warnings in the processoutput. As long as you see the log line shown above, you can safelyignore these warnings during your initial evaluation of MongoDB.
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.
Additional Considerations
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.