MongoDB Installation Steps on Windows Server
A. Installing MongoDB on Windows
The version featured in this book is MongoDB 4.0. The minimum requirement for a Windows installation is Windows Server 2008 R2, Windows 7, or later.
Download and install
To download and install MongoDB on Windows, proceed as follows:
1. Go to the MongoDB download center at: https://www.mongodb.com/download- center#community.
2. Select the appropriate operating system where it says Version.
3. Click on DOWNLOAD:
4. When prompted, choose Save File.
5. Click on the saved MSI file to start the installer.
6. Click OK when the security prompt appears asking to Open Executable File?
7. Click Run when the security warning appears.
8. Click Next to start the MongoDB Setup Wizard.
9. Read the license agreement and click on the checkbox and Next. Note that if you do not accept the license agreement the installation will terminate.
10. When asked Choose Setup Type, for the purposes of this illustration, select Complete. MongoDB Compass, which is a handy utility which greatly facilitates database management, is automatically installed.
11. Now that all choices have been made, click on Install and click Yes when the User Account Control security warning pops up.
12. As of MongoDB v4.0, the installation wizard lets you configure startup options. If you want to have MongoDB start automatically and run in the background, choose Run service as Network Service user. You can also configure the directory where MongoDB stores its data files (Data Directory), and where log files are stored (Log Directory):
13. Click Next to continue and Finish when the installation completes.
B. Installing MongoDB on Linux
It is important to understand the MongoDB installation process on Linux, even if you are a developer or IT professional and are not using Linux personally, it’s extremely likely that the internet-facing server you or your customer use is running Linux. W3Techs (https:// w3techs.com/), a company that does web technology surveys, estimates that in 2018, the running on Linux was at 68.1% compared with 32% for Windows. There are three primary considerations when installing MongoDB on Linux, each of which we will address in turn:
- Linux based upon Debian and Ubuntu
- Linux based upon RedHat, Fedora, and CentOS
- Installing directly from source code.
Installing on Debian or Ubuntu Linux
Debian Linux (https://www.debian.org/), self-described as the universal operating system, is a free open-source project that uses a fork of the Linux kernel, and draws heavily upon GNU (http://www.gnu.org/software/software.html, for example, GNU Not Unix) software. Ubuntu Linux (https://www.ubuntu.com/) is produced by the Canonical Group Ltd based in South Africa, and is based upon Debian. For the purposes of this book, we will focus on Ubuntu version 18.04, code-named Bionic Beaver, released in April 2018, a designated LTS (Long Term Support) version.
The preferred way to install any given software on Ubuntu is to use a Debian package. Such packages have the extension *.deb and include a script that tells the package management program where to place the pre-compiled binary files as they are extracted. Popular package management programs include synaptic (http://www.nongnu. org/synaptic/, graphical interface, resolves dependencies, and does a lot of “housekeeping”), aptitude (https://help.ubuntu.com/lts/serverguide/aptitude.html, like synaptic but has a textual, command-line menu), and apt-* (that is apt-get (https:// linux.die.net/man/8/apt-get), apt-key so on: very fast, command-line only). For the purposes of this section we will use apt-get.
The MongoDB packages available for Ubuntu/Debian include the following:
mongodb-org-server | Primary MongoDB system daemon |
mongodb-org-mongos | MongoDB shard routing service |
mongodb-org-shell | MongoDB shell |
mongodb-org-tools | Provides various mongo* tools for import, export, restore, and so on. |
In addition, a composite package, mongodb-org, which contains all four of these packages, is provided.
Package installation
To install MongoDB on an Ubuntu/Debian server, you will need root access. A unique feature of Debian-based Linux distributions is that direct login as root is not allowed for security reasons. Accordingly, you can promote yourself to root using su, or you can precede the various commands with sudo, which instructs the OS to process this command as root.
Please proceed as follows:
1. Import the public key from the MongoDB key server. This is needed so that the package manager can authenticate the MongoDB package: 2. Add the MongoDB repository to the Linux server's sources list: 3. Refresh the package database from the sources list by running: sudo apt-get update
4. Install the latest (stable) version of MongoDB. Here, we install only the composite package, which alleviates the need to separately install the four primary packages listed previously:
sudo apt-get install -y mongodb-org