在 SUSE 上安装 MongoDB Enterprise Edition

在本页面

Overview

使用本教程,可以使用zypper程序包 Management 器在 SUSE Linux Enterprise Server(SLES)上安装 MongoDB 3.6 Enterprise Edition。

MongoDB 企业版在某些平台上可用,并且包含对与安全性和监视有关的多种功能的支持。

MongoDB Version

本教程将安装 MongoDB 3.6 Enterprise Edition。要安装其他版本的 MongoDB Enterprise,请使用此页面左上角的版本下拉菜单选择该版本的文档。

Considerations

Platform Support

EOL Notice

  • MongoDB 3.6.17 企业版删除了s390x上对 SLES 12 的支持

  • MongoDB 3.6.4 企业版删除了x86_64s390x上对 SLES 11 的支持

MongoDB 3.6 Enterprise Edition 在x86_64体系结构上支持以下 64 位 SUSE Linux Enterprise Server(SLES)版本:

  • SLES 12-适用于 MongoDB 版本 3.6.0-3.6.16 。 SLES 12 上不支持较新的 MongoDB 3.6 版本。请考虑升级到 MongoDB 4.0 或更高版本。

MongoDB 仅支持此平台的 64 位版本。

有关更多信息,请参见Supported Platforms

Windows Subsystem for Linux (WSL) - Unsupported

MongoDB 不支持 Linux 的 Windows 子系统(WSL)。

Production Notes

在生产环境中部署 MongoDB 之前,请考虑Production Notes文档,该文档提供了生产 MongoDB 部署的性能注意事项和配置建议。

安装 MongoDB 企业版

请按照以下步骤使用zypper程序包 Management 器安装 MongoDB 企业版。

导入 MongoDB 公钥

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

配置程序包 Management 系统(zypper)。

添加存储库,以便您可以使用zypper安装 MongoDB。

运行适合您的 SUSE 版本的命令:

  • SUSE 12

sudo zypper addrepo --gpgcheck“ https://repo.mongodb.com/zypper/suse/12/mongodb-enterprise/3.6/x86_64/” mongodb


 

If you'd like to install MongoDB packages from a previous [release series](reference-versioning.html#release-version-numbers) such as 3\.4, you can specify the release series in the repository configuration\. For example, to restrict your SUSE 12 system to the 3\.4 release series, use the following command:

 

```sh
sudo zypper addrepo --no-gpgcheck https://repo.mongodb.com/zypper/suse/12/mongodb-enterprise/3.4/x86_64/ mongodb

安装 MongoDB 软件包。

要安装 MongoDB 3.6,请发出以下命令:

sudo zypper -n install mongodb-enterprise

要安装特定版本的 MongoDB,请分别指定每个组件软件包,并将版本号附加到软件包名称中,如以下示例所示:

sudo zypper install mongodb-enterprise-3.6.19 mongodb-enterprise-server-3.6.19 mongodb-enterprise-shell-3.6.19 mongodb-enterprise-mongos-3.6.19 mongodb-enterprise-tools-3.6.19

您可以指定任何可用的 MongoDB 版本。但是,zypper将在更新版本可用时升级软件包。为防止意外升级,请通过运行以下命令来固定软件包:

sudo zypper addlock mongodb-enterprise-3.6.19 mongodb-enterprise-server-3.6.19 mongodb-enterprise-shell-3.6.19 mongodb-enterprise-mongos-3.6.19 mongodb-enterprise-tools-3.6.19

MongoDB 软件包的早期版本使用不同的存储库位置。请参阅适合您的 MongoDB 版本的文档版本。

运行 MongoDB 企业版

默认情况下,MongoDB 实例存储:

  • /var/lib/mongo中的数据文件

  • 其日志文件位于/var/log/mongodb

如果通过程序包 Management 器安装,则这些默认目录是在安装过程中创建的。

如果通过下载压缩包手动安装,则可以使用mkdir -p <directory>sudo mkdir -p <directory>创建目录,具体取决于将运行 MongoDB 的用户。 (有关mkdirsudo的信息,请参见您的 Linux 手册页.)

默认情况下,MongoDB 使用mongod用户帐户运行。如果您更改运行 MongoDB 进程的用户,则必须**还修改对/var/lib/mongo/var/log/mongodb目录的权限,以使该用户可以访问这些目录。

要指定其他日志文件目录和数据文件目录,请编辑/etc/mongod.conf中的systemLog.pathstorage.dbPath设置。确保运行 MongoDB 的用户有权访问这些目录。

大多数类 Unixos 都限制了会话可能使用的系统资源。这些限制可能会对 MongoDB 的运行产生负面影响。有关更多信息,请参见UNIX ulimit 设置

Procedure

请按照以下步骤运行 MongoDB 企业版。这些说明假定您使用的是默认设置。

Init System

要运行和 Managementmongod进程,您将使用 os 的内置init system。最新版本的 Linux 倾向于使用 systemd (使用systemctl命令),而较早版本的 Linux 倾向于使用 System V init (使用service命令)。

如果不确定平台使用哪个初始化系统,请运行以下命令:

ps --no-headers -o comm 1

然后根据结果在下面选择适当的选项卡:

  • systemd-选择下面的“ systemd(systemctl)”标签。

  • init-选择下面的“系统 V 初始化(服务)”标签。

systemd (systemctl)
System V Init (service)

Start MongoDB.

You can start the mongod process by issuing the following command:

sudo systemctl start mongod

If you receive an error similar to the following when starting mongod:

Failed to start mongod.service: Unit mongod.service not found.

Run the following command first:

sudo systemctl daemon-reload

Then run the start command above again.

Verify that MongoDB has started successfully.

You can verify that the mongod process has started successfully by issuing the following command:

sudo systemctl status mongod

You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

sudo systemctl enable mongod

Stop MongoDB.

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

sudo systemctl stop mongod

Restart MongoDB.

You can restart the mongod process by issuing the following command:

sudo systemctl restart mongod

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. Use the --host command line option to specify the localhost address and port that the mongod listens on:

mongo --host 127.0.0.1:27017

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

Start MongoDB.

You can start the mongod process by issuing the following command:

sudo service mongod start

Verify that MongoDB has started successfully

You can verify that the mongod process has started successfully 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 system reboot by issuing the following command:

sudo chkconfig mongod on

Stop MongoDB.

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

sudo service mongod stop

Restart MongoDB.

You can restart the mongod process by issuing the following command:

sudo service mongod restart

You can follow the state of the process for errors or important messages by watching the output in the /var/log/mongodb/mongod.log file.

Begin using MongoDB.

Start a mongo shell on the same host machine as the mongod. Use the --host command line option to specify the localhost address and port that the mongod listens on:

mongo --host 127.0.0.1:27017

Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

Uninstall MongoDB

要从系统中完全删除 MongoDB,必须删除 MongoDB 应用程序本身,配置文件以及任何包含数据和日志的目录。以下部分将指导您完成必要的步骤。

Warning

此过程将“完全”删除 MongoDB,其配置和“所有”数据库。此过程是不可逆的,因此请确保在 continue 操作之前备份所有配置和数据。

Stop MongoDB.

通过发出以下命令来停止mongod进程:

sudo service mongod stop

Remove Packages.

删除以前安装的所有 MongoDB 软件包。

sudo zypper remove $(rpm -qa | grep mongodb-enterprise)

删除数据目录。

删除 MongoDB 数据库和日志文件。

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongo

Additional Information

默认情况下,localhost 绑定

默认情况下,MongoDB 在bindIp设置为127.0.0.1的情况下启动,该绑定到 localhost 网络接口。这意味着mongod仅可以接受来自同一计算机上运行的 Client 端的连接。远程 Client 端将无法连接到mongod,并且mongod将无法初始化replica set,除非将此值设置为有效的网络接口。

可以配置此值:

  • 在带有bindIp的 MongoDB 配置文件中,或者

  • 通过命令行参数--bind_ip

Warning

绑定到非 localhost(例如可公开访问)的 IP 地址之前,请确保已保护群集免受未经授权的访问。有关安全建议的完整列表,请参见Security Checklist。至少考虑enabling authentication加强网络基础设施

有关配置bindIp的更多信息,请参见MongoDB 配置强化

MongoDB 企业版软件包

MongoDB Enterprise Edition 可从其自己的专用存储库中获得,并且包含以下官方支持的软件包:

Package NameDescription
mongodb-enterprisemetapackage将自动安装下面列出的四个组件包。
mongodb-enterprise-server包含mongod守护程序以及相关的配置和初始化脚本。
mongodb-enterprise-mongos包含mongos守护程序。
mongodb-enterprise-shell包含mongo shell。
mongodb-enterprise-tools包含以下 MongoDB 工具:mongoimport bsondumpmongodumpmongoexportmongofilesmongoperfmongorestoremongostatmongotop