Database Manual / Self-Managed Deployments / Storage / Storage Engines / WiredTiger

Change a Self-Managed Replica Set to WiredTiger将自我管理副本集更改为WiredTiger

Note

  • The noPadding and usePowerOf2Sizes MMAPv1 options for the collMod command are removed.
  • 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 update a replica set to use WiredTiger. The procedure updates the replica set in a rolling fashion to avoid downtime.使用本教程更新副本集以使用WiredTiger。该过程以滚动方式更新副本集,以避免停机。

Considerations注意事项

Replica sets can have members with different storage engines. As such, you can update members to use the WiredTiger storage engine in a rolling fashion.副本集可以包含具有不同存储引擎的成员。因此,您可以更新成员以滚动方式使用WiredTiger存储引擎。

PSA 3-member ArchitecturePSA三人架构

The "majority" read concern, available for WiredTiger, is enabled by default. 默认情况下,WiredTiger启用了"majority"读取关注。However, in three-member replica sets with a primary-secondary-arbiter (PSA) architecture, you can disable the "majority" read concern. 然而,在具有主从仲裁器(PSA)架构的三成员副本集中,您可以禁用"majority"读取关注。Disabling the "majority" read concern for a three-member PSA architecture avoids possible cache-pressure build up.禁用三成员PSA架构的"majority"读取关注可以避免可能的缓存压力积聚。

The procedure below disables "majority" read concern for PSA architecture by including --enableMajorityReadConcern false.以下过程通过包含--enableMajorityReadConcern false来禁用PSA架构的"majority"读取关注。

Note

Disabling "majority" read concern has no effect on change streams availability.禁用"majority"读取关注不会影响更改流的可用性。

For more information on PSA architecture and read concern "majority", see Primary-Secondary-Arbiter Replica Sets.有关PSA架构的更多信息,请读取关注"majority",请参阅主从仲裁器副本集

Default Bind to Localhost默认绑定到本地主机

MongoDB binaries, mongod and mongos, bind to localhost by default.MongoDB二进制文件mongodmongos默认绑定到localhost

XFS and WiredTiger

With the WiredTiger storage engine, using XFS for data bearing nodes is recommended on Linux. For more information, see Kernel and File Systems.对于WiredTiger存储引擎,建议在Linux上使用XFS作为数据承载节点。有关更多信息,请参阅内核和文件系统

MMAPv1 Only Restrictions仅MMAPv1限制

Once upgraded to WiredTiger, your WiredTiger deployment is not subject to the following MMAPv1-only restrictions:升级到WiredTiger后,WiredTiger部署不受以下仅限MMAPv1的限制:

MMAPv1 Restrictions限制Short Description简短描述
Number of Namespaces命名空间数量For MMAPv1, the number of namespaces is limited to the size of the namespace file divided by 628.对于MMAPv1,命名空间的数量限制为命名空间文件的大小除以628。
Size of Namespace File命名空间文件的大小For MMAPv1, namespace files can be no larger than 2047 megabytes.对于MMAPv1,命名空间文件不能大于2047 MB。
Database Size数据库大小The MMAPv1 storage engine limits each database to no more than 16000 data files.MMAPv1存储引擎将每个数据库限制为不超过16000个数据文件。
Data Size数据大小For MMAPv1, a single mongod instance cannot manage a data set that exceeds maximum virtual memory address space provided by the underlying operating system.对于MMAPv1,单个mongod实例无法管理超过底层操作系统提供的最大虚拟内存地址空间的数据集。
Number of Collections in a Database数据库中的集合数For the MMAPv1 storage engine, the maximum number of collections in a database is a function of the size of the namespace file and the number of indexes of collections in the database.对于MMAPv1存储引擎,数据库中集合的最大数量是命名空间文件大小和数据库中集合索引数量的函数。

Procedure过程

The following procedure updates the replica set in a rolling fashion. 以下过程以滚动方式更新副本集。The procedure updates the secondary members first, then steps down the primary, and updates the stepped-down member.该过程首先更新次要成员,然后逐步减少primary成员,并更新已减少的成员。

To update a member to WiredTiger, the procedure removes a member's data, starts mongod with WiredTiger, and performs an initial sync.若要将成员更新为WiredTiger,该过程将删除成员的数据,使用WiredTiger启动mongod,并执行初始同步

A. Update the secondary members to WiredTiger.将次要成员更新为WiredTiger。

Update the secondary members one at a time:一次更新一个次要成员:

1

Shut down the secondary member.关闭次要成员。

In mongosh, shut down the secondary.mongosh中,关闭secondary。

use admin
db.shutdownServer()
2

Prepare a data directory for the new mongod running with WiredTiger.为使用WiredTiger运行的新mongod准备一个数据目录。

Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine. 为将与WiredTiger存储引擎一起运行的新mongod实例准备一个数据目录。mongod must have read and write permissions for this directory. You can either delete the contents of the stopped secondary member's current data directory or create a new directory entirely.mongod必须具有此目录的读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。

mongod with WiredTiger will not start with data files created with a different storage engine.带有WiredTiger的mongod不会从使用不同存储引擎创建的数据文件开始。

3

Update configuration for WiredTiger.更新WiredTiger的配置。

Remove any MMAPv1 configuration options from the mongod instance configuration.mongod实例配置中删除所有MMAPv1配置选项。

4

Start mongod with WiredTiger.用WiredTiger开始mongod

Start mongod, specifying wiredTiger as the --storageEngine and the prepared 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.至少,考虑启用身份验证并加强网络基础设施

General Use (For Most Architectures)一般用途(适用于大多数架构)
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)>
PSA ArchitecturePSA架构

Important

If you are running a three-member PSA architecture, include --enableMajorityReadConcern false to disable read concern majority. See PSA 3-member Architecture.如果您正在运行一个由三个成员组成的PSA架构,请包含--enableMajorityReadConcern false以禁用读取关注majority。请参阅PSA 3人架构

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern false

Since no data exists in the --dbpath, the mongod will perform an initial sync. 由于--dbpath中没有数据,mongod将执行初始同步。The length of the initial sync process depends on the size of the database and network connection between members of the replica set.初始同步过程的长度取决于数据库的大小和副本集成员之间的网络连接。

You can also specify the options in a configuration file. 您还可以在配置文件中指定选项。To specify the storage engine, use the storage.engine setting.要指定存储引擎,请使用storage.engine设置。

Repeat the steps for the remaining secondary members, updating them one at a time.对剩余的次要成员重复这些步骤,一次更新一个。

B. Step down the primary.退出primary。

Important

If updating all members of the replica set to use WiredTiger, ensure that all secondary members have been updated first before updating the primary.如果将副本集的所有成员更新为使用WiredTiger,请确保在更新主成员之前首先更新了所有辅助成员。

Once all the secondary members have been upgraded to WiredTiger, connect mongosh to the primary and use rs.stepDown() to step down the primary and force an election of a new primary.一旦所有次要成员都升级到WiredTiger,将mongosh连接到主要成员,并使用rs.stepDown()退出主要成员并强制选举新的主要成员。

rs.stepDown()

C. Update the stepped down primary.更新已降级的初选。

When the primary has stepped down and become a secondary, update the secondary to use WiredTiger as before:当主节点降级为次节点时,更新次节点以使用WiredTiger,如前所述:

1

Shut down the secondary member.关闭次要成员。

In mongosh, shut down the secondary.mongosh中,关闭secondary。

use admin
db.shutdownServer()
2

Prepare a data directory for the new mongod running with WiredTiger.为使用WiredTiger运行的新mongod准备一个数据目录。

Prepare a data directory for the new mongod instance that will run with the WiredTiger storage engine. 为将与WiredTiger存储引擎一起运行的新mongod实例准备一个数据目录。mongod must have read and write permissions for this directory. You can either delete the contents of the stopped secondary member's current data directory or create a new directory entirely.mongod必须具有此目录的读写权限。您可以删除已停止的辅助成员当前数据目录的内容,也可以完全创建一个新目录。

mongod with WiredTiger will not start with data files created with a different storage engine.使用WiredTiger不会从使用其他存储引擎创建的数据文件开始。

3

Update configuration for WiredTiger.更新WiredTiger的配置。

Remove any MMAPv1 configuration options from the mongod instance configuration.mongod实例配置中删除所有MMAPv1配置选项。

4

Start mongod with WiredTiger.用WiredTiger开始mongod

Start mongod, specifying wiredTiger as the --storageEngine and the prepared 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.至少,考虑启用身份验证加强网络基础设施

General Use (For Most Architectures)一般用途(适用于大多数架构)
mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)>
PSA ArchitecturePSA架构

Important

If you are running a three-member PSA architecture, include --enableMajorityReadConcern false to disable read concern majority. 如果您正在运行一个由三个成员组成的PSA架构,请包含--enableMajorityReadConcern false以禁用读取关注majoritySee PSA 3-member Architecture.请参阅PSA 3人架构

mongod --storageEngine wiredTiger --dbpath <newWiredTigerDBPath> --replSet <replSetName> --bind_ip localhost,<hostname(s)|ip address(es)> --enableMajorityReadConcern false

Since no data exists in the --dbpath, the mongod will perform an initial sync. 由于--dbpath中没有数据,mongod将执行初始同步The length of the initial sync process depends on the size of the database and network connection between members of the replica set.初始同步过程的长度取决于数据库的大小和副本集成员之间的网络连接。

You can also specify the options in a configuration file. 您还可以在配置文件中指定选项。To specify the storage engine, use the storage.engine setting.要指定存储引擎,请使用storage.engine设置。