Note
You must upgrade to WiredTiger. MongoDB removed the deprecated MMAPv1 storage engine in version 4.2.您必须升级到WiredTiger。MongoDB在4.2版本中删除了弃用的MMAPv1存储引擎。
Use this tutorial to change the storage engine of a standalone MongoDB instance to WiredTiger.使用本教程将独立MongoDB实例的存储引擎更改为WiredTiger。
Considerations注意事项
mongodump and 和mongorestore
This tutorial uses the 本教程使用mongodump and mongorestore utilities to export and import data.mongodump和mongorestore实用程序导出和导入数据。
Ensure that these MongoDB package components are installed and updated on your system.确保在系统上安装并更新了这些MongoDB包组件。Make sure you have sufficient drive space available for the确保您有足够的驱动器空间用于mongodumpexport file and the data files of your newmongodinstance running with WiredTiger.mongodump导出文件和使用WiredTiger运行的新mongod实例的数据文件。
Default Bind to Localhost默认绑定到本地主机
MongoDB binaries, MongoDB二进制文件mongod and mongos, bind to localhost by default.mongod和mongos默认绑定到localhost。
The tutorial runs 本教程从与它们连接的mongodump and mongorestore from the same host as the mongod they are connecting to. mongod相同的主机运行mongodump和mongorestore。If run remotely, 如果远程运行,mongodump and mongorestore must specify the ip address or the associated hostname in order to connect to the mongod.mongodump和mongorestore必须指定ip地址或相关主机名才能连接到mongod。
XFS and 和WiredTiger
With the WiredTiger storage engine, using XFS for data bearing nodes is recommended on Linux. 对于WiredTiger存储引擎,建议在Linux上使用XFS作为数据承载节点。For more information, see Kernel and File Systems.有关更多信息,请参阅内核和文件系统。
MMAPv1 Only Restrictions仅限限制
Once upgraded to WiredTiger, your WiredTiger deployment is not subject to the following MMAPv1-only restrictions:升级到WiredTiger后,WiredTiger部署不受以下仅限MMAPv1的限制:
| MMAPv1 | |
|---|---|
mongod instance cannot manage a data set that exceeds maximum virtual memory address space provided by the underlying operating system.mongod实例无法管理超过底层操作系统提供的最大虚拟内存地址空间的数据集。 | |
Procedure过程
Start the mongod you wish to change to WiredTiger.启动您要更改为WiredTiger的mongod。
mongod you wish to change to WiredTiger.If 如果mongod is already running, you can skip this step.mongod已经在运行,则可以跳过此步骤。
Export data using mongodump.使用mongodump导出数据。
mongodump.mongodump --out=<exportDataDestination>
Specify additional options as appropriate, such as username and password if running with authorization enabled. 根据需要指定其他选项,例如在启用授权的情况下运行时的用户名和密码。See 有关可用选项,请参阅mongodump for available options.mongodump。
Create a data directory for the new mongod running with WiredTiger.为使用WiredTiger运行的新mongod创建一个数据目录。
mongod running with WiredTiger.Create a data directory for the new 为将与WiredTiger存储引擎一起运行的新mongod instance that will run with the WiredTiger storage engine. mongod实例创建一个数据目录。mongod must have read and write permissions for this directory.mongod必须具有此目录的读写权限。
带有WiredTiger的mongod with WiredTiger will not start with data files created with a different storage engine.mongod不会从使用不同存储引擎创建的数据文件开始。
Update configuration for WiredTiger.更新WiredTiger的配置。
Remove any MMAPv1 configuration options from the 从mongod instance configuration.mongod实例配置中删除所有MMAPv1配置选项。
Start mongod with WiredTiger.用WiredTiger开始mongod。
mongod with WiredTiger.Start 启动mongod, specifying wiredTiger as the --storageEngine and the newly created data directory for WiredTiger as the --dbpath.mongod,将wiredTiger指定为--storageEngine,将新创建的wiredTiger数据目录指定为--dbpath。
Specify additional options as appropriate, such as 根据需要指定其他选项,例如--bind_ip.--bind_ip。
Warning
Before you bind your instance to a publicly-accessible IP address, you must secure your cluster from unauthorized access. 在将实例绑定到可公开访问的IP地址之前,必须保护集群免受未经授权的访问。For a complete list of security recommendations, see Security Checklist for Self-Managed Deployments. 有关安全建议的完整列表,请参阅自我管理部署的安全检查表。At minimum, consider enabling authentication and hardening network infrastructure.至少,考虑启用身份验证并加强网络基础设施。
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --bind_ip localhost,<hostname(s)|ip address(es)>
You can also specify the options in a configuration file. 您还可以在配置文件中指定选项。To specify the storage engine, use the 要指定存储引擎,请使用storage.engine setting.storage.engine设置。
Upload the exported data using mongorestore.使用mongorestore上传导出的数据。
mongorestore.mongorestore <exportDataDestination>
Specify additional options as appropriate. 根据需要指定其他选项。See 有关可用选项,请参阅mongorestore for available options.mongorestore。