注意
您必须升级到 WiredTiger。MongoDB 移除了版本 4.2 中已弃用的 MMAPv1 storage engine。
使用本教程将独立 MongoDB 实例的存储引擎更改为 WiredTiger。
Considerations
mongodump 和 mongorestore
This tutorial uses the mongodump and mongorestore utilities to export and import data.
确保在系统中安装并更新了这些 MongoDB 程序包组件。
默认绑定至本地主机
默认情况下,MongoDB 二进制文件 mongod 和 mongos 绑定到 localhost。
The tutorial runs mongodump and mongorestore from the same host as the mongod they are connecting to. If run remotely, mongodump and mongorestore must specify the ip address or the associated hostname in order to connect to the mongod.
XFS 和 WiredTiger
对于 WiredTiger 存储引擎,建议在 Linux 上使用 XFS 作为数据承载节点。有关详情,请参阅内核和文件系统。
仅限于 MMAPv1 限制
升级到 WiredTiger 后,WiredTiger 部署不受以下仅限于 MMAPv1 限制的约束:
MMAPv1 限制 | 简短描述 |
|---|---|
命名空间数 | 对于 MMAPv1,命名空间的数量限制为命名空间文件的大小除以 628。 |
命名空间文件的大小 | 对于 MMAPv1,命名空间文件的大小不得超过 2047 兆字节。 |
数据库大小 | MMAPv1 存储引擎将每个数据库限制为不超过 16000 个数据文件。 |
数据大小 | 对于 MMAPv1,单个 |
数据库中的集合数量 | 对于 MMAPv1 存储引擎,数据库中集合的最大数量是命名空间文件大小和数据库中集合索引数量的函数。 |
步骤
mongod启动要更改为WiredTiger的 。
如果 mongod 已经运行,则可以跳过此步骤。
使用mongodump 导出数据。
mongodump --out=<exportDataDestination>
Specify additional options as appropriate, such as username and password if running with authorization enabled. See mongodump for available options.
为使用WiredTiger运行的新 mongod 创建数据目录。
为将使用 WiredTiger 存储引擎运行的新 mongod 实例创建一个数据目录。mongod 必须具有此目录的读写权限。
mongod 带有 WiredTiger,不会启动使用其他存储引擎创建的数据文件。
更新 WiredTiger 的配置。
从 mongod 实例配置中删除任何 MMAPv1 配置选项。
mongod使用WiredTiger启动 。
启动 mongod,指定 wiredTiger 为 --storageEngine,为 WiredTiger 新建的数据目录为 --dbpath。
根据需要指定其他选项,如 --bind_ip。
警告
将实例绑定到可公开访问的 IP 地址之前,必须保护集群免遭未经授权的访问。有关安全建议的完整列表,请参阅自管理部署的安全清单。至少应考虑启用身份验证和强化网络基础设施。
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --bind_ip localhost,<hostname(s)|ip address(es)>
您也可以在配置文件中指定这些选项。要指定存储引擎,请使用 storage.engine 设置。
使用mongorestore 上传导出的数据。
mongorestore <exportDataDestination>
Specify additional options as appropriate. See mongorestore for available options.