Install MongoDB Community Edition on SUSE

Overview

The following tutorial uses a package manager to install MongoDB4.2 Community Edition on SUSE Linux Enterprise Server (SLES)12. If you choose to install by directly downloading the .tgz file,see Install MongoDB Community using .tgz Tarball on SUSE.

This installation guide only supports 64-bit systems. SeeSupported Platforms for more information.

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.

Windows Subsystem for Linux (WSL) - Unsupported

MongoDB does not support WSL, and users on WSL have encounteredvarious issues installing on WSL. For examples, see:

Considerations

Note

SUSE Linux Enterprise Server and potentially other SUSE distributions shipwith virtual memory address space limited to 8 GB by default. You _must_adjust this in order to prevent virtual memory allocation failures as thedatabase grows.

The SLES packages for MongoDB automatically adjust these limits intheir default init script. If you are starting MongoDB manually withoutthe provided init script, are using your own custom init script, orare using the TGZ tarball release, you must make these changesyourself.

Production Notes

Before deploying MongoDB in a production environment, consider theProduction Notes document.

Install Using .rpm Packages

Import the MongoDB public key

  1. sudo rpm --import https://www.mongodb.org/static/pgp/server-4.2.asc

Configure the package management system (zypper).

Add the repository so that you can install MongoDB using zypper.

For MongoDB 4.2

Run the following command:

  1. sudo zypper addrepo --gpgcheck "https://repo.mongodb.org/zypper/suse/12/mongodb-org/4.2/x86_64/" mongodb

For versions of MongoDB earlier than 4.2

To install MongoDB packages from a previous releaseseries such as 3.4, you canspecify the release series in the repository configuration.

For example, to restrict your SUSE 12 system to the 3.4 releaseseries, use the following command:

  1. sudo zypper addrepo --no-gpgcheck https://repo.mongodb.org/zypper/suse/12/mongodb-org/3.4/x86_64/ mongodb

Install the MongoDB packages.

To install the latest version of MongoDB, issue the followingcommand:

  1. sudo zypper -n install mongodb-org

To install a specific release of MongoDB, specify eachcomponent package individually and append the version number to thepackage name, as in the following example:

  1. sudo zypper install mongodb-org-4.2.1 mongodb-org-server-4.2.1 mongodb-org-shell-4.2.1 mongodb-org-mongos-4.2.1 mongodb-org-tools-4.2.1

You can specify any available version of MongoDB. However zypperupgrades the packages when a newer version becomes available. Toprevent unintended upgrades, pin the packages by running the followingcommand:

  1. sudo zypper addlock mongodb-org-4.2.1 mongodb-org-server-4.2.1 mongodb-org-shell-4.2.1 mongodb-org-mongos-4.2.1 mongodb-org-tools-4.2.1

Previous versions of MongoDB packages use a different repository location.Refer to the version of the documentation appropriate foryour MongoDB version.

Run MongoDB Community Edition

  • Production Notes
  • Before deploying MongoDB in a production environment, consider theProduction Notes document.
  • ulimit Considerations
  • 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.
  • Directories
  • By default, MongoDB instance stores:

    • its data files in /var/lib/mongo
    • its log files in /var/log/mongodbIf 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/mongodbdirectories 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.

Procedure

Note

The following instructions assume that you have downloaded theofficial MongoDB packages.

Start MongoDB.

You can start the mongod process by issuing the followingcommand:

  1. 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.logfor a line reading

  1. [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:

  1. sudo chkconfig mongod on

Stop MongoDB.

As needed, you can stop the mongod process by issuing thefollowing command:

  1. sudo service mongod stop

Restart MongoDB.

You can restart the mongod process by issuing the followingcommand:

  1. 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:

  1. mongo

For more information on connecting using the mongoshell, 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 Community Edition

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:

  1. sudo service mongod stop

Remove Packages.

Remove any MongoDB packages that you had previously installed.

  1. sudo zypper remove $(rpm -qa | grep mongodb-org)

Remove Data Directories.

Remove MongoDB databases and log files.

  1. sudo rm -r /var/log/mongodb
  2. sudo rm -r /var/lib/mongo

Additional Information

Packages

MongoDB provides officially supported packages in their own repository:

Package NameDescription
mongodb-orgA metapackage that will automatically installthe four component packages listed below.
mongodb-org-serverContains the mongod daemon, associated initscript, and a configuration file (/etc/mongod.conf). Youcan use the initialization script to start mongodwith the configuration file. For details, see Run MongoDBCommunity Edition.
mongodb-org-mongosContains the mongos daemon.
mongodb-org-shellContains the mongo shell.
mongodb-org-toolsContains the following MongoDB tools: mongoimportbsondump, mongodump, mongoexport,mongofiles,mongorestore, mongostat,and mongotop.